2011-12-27 6 views
0

マイコード:TreegridはどのようにローカルのJSON(メモリプロキシ)を使用

Ext.onReady(function() { 
    Ext.define('Unit', { 
     extend: 'Ext.data.Model', 
     fields: [ 
      {name: 'task',type: 'string'} 
     ] 
    }); 

    var store = Ext.create('Ext.data.TreeStore', { 
     autoLoad: true, 
     model: 'Unit', 
     data:result, 
     proxy: { 
      type: 'memory', 
      reader: { 
       type: 'json' 
      } 
     } 
    }); 
    var tree = Ext.create('Ext.tree.Panel', { 
     id:"treepanel", 
     title: 'Core Team Projects', 
     width: 500, 
     height: 300, 
     renderTo: Ext.getBody(), 
     collapsible: true, 
     useArrows: true, 
     rootVisible: false, 
     store: store, 
     multiSelect: true, 
     singleExpand: true, 
     //the 'columns' property is now 'headers' 
     columns: [{ 
      xtype: 'treecolumn', //this is so we know which column will show the tree 
      text: 'Task', 
      flex: 2, 
      sortable: true, 
      dataIndex: 'task' 
     },{ 
      //we must use the templateheader component so we can use a custom tpl 
      xtype: 'treecolumn', 
      text: 'Duration', 
      flex: 1, 
      sortable: true, 
      dataIndex: 'duration', 
      align: 'center' 
     }] 
    }); 
}); 

JSONです:http://dev.sencha.com/deploy/ext-4.0.0/examples/tree/treegrid.json

私の結果を表示しないツリー、どのようにそれを行うには?私は新しいExtJs4です。

申し訳ありません申し訳ありませんが、結果を得るためにAJAXを使用しません。

答えて

0

JSONファイルを使用すると、タイプを使用する必要が同じドメイン上にない場合:「JSONP」

0

は、以下のリンクを参照してください。 Ext JSでクライアントプロキシについて明確なアイデアを得ることができます。

http://www.pointerunits.com/2013/01/ext-js4-client-proxies.html

あなたのデータがサーバーに存在している場合は、サーバーからデータをロードするためのいずれかのサーバープロキシを使用する必要があります。

のAjaxプロキシー - データをロードする場合
JSONPプロキシAJAX呼び出しを使用して - 別のサーバーからデータをロードするための
休憩プロキシ(CORS問題を回避するため) - データをロードするためのRESTサービスを呼び出すことによって。

0

data属性は、プロキシの内部で宣言する必要があります(Fiddle)前

var store = Ext.create('Ext.data.TreeStore', { 
    model: 'Unit', 
    data: result, 
    proxy: { 
     type: 'memory', 
     reader: { 
      type: 'json' 
     } 
    } 
}); 

後:(Fiddle):

var store = Ext.create('Ext.data.TreeStore', { 
    model: 'Unit', 
    proxy: { 
     type: 'memory', 
     data: result, 
     reader: { 
      type: 'json' 
     } 
    } 
}); 

出来上がり!

関連する問題