1

私はまだ Extjs の初心者です。JSON 文字列を入力として読み取る TreeStore があり、それをツリー パネルで表すことができます。しかし、ツリー ピッカーでツリーストアを使用しようとすると、次のエラーが発生します。

ここに欠けているものはありますか?

// try to find a record in the store that matches the value
        record = value ? me.store.getNodeById(value) : me.store.getRootNode();

JSON 形式は次のとおりです。

{
  success: true,
  "children": [
    {
      "id": "G_1",
      "text": "group1",
      "leaf": false
    }, 
    {
      "id": "G_2",
      "text": "group2",
      "leaf": false
     }
  ]
}

そして、ここに私のTreeStoreがあります:

Ext.define('App.store.GroupTree', {
    extend: 'Ext.data.TreeStore',
    model: 'App.model.GroupTree',
    requires: 'App.model.GroupTree',
    proxy: {
        type: 'ajax',
        url: 'property/tree.json',
        reader: {  
            type: 'json',
            root:'children'
        }
    },
});

私のツリーピッカーアイテム:

items: [
  {  
    xtype: 'treepicker',
    name: 'propertyCmb',
    fieldLabel: 'Property',
    labelWidth: 60,
    displayField: 'text',
    store: 'GroupTree',
    valueField: 'id',
    queryMode: 'local',
  }
]

これがtreestoreモデルコードです

Ext.define('App.model.GroupTree', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id', type: 'string', useNull: true},
        {name: 'text', type: 'string'},
        {name: 'leaf', type: 'boolean'},
        {name: 'expanded', type: 'boolean'}
    ]
});
4

1 に答える 1

0

のようなツリーピッカーに割り当てられたときにストアが自動作成されないため、エラーが発生しますstore: 'GroupTree'。最初にそのインスタンスを作成し、そのインスタンスをツリーピッカーに割り当てる必要があります。ドキュメントhttp://docs.sencha.com/extjs/5.0.1/#!/api/Ext.ux.TreePicker-cfg-storeを参照してください。

以下は動作するはずです

var groupStore = Ext.create('App.store.GroupTree');
groupStore.load();

var picker = Ext.create('Ext.ux.TreePicker',{
  name: 'propertyCmb',
  store: groupStore,
  fieldLabel: 'Property',
  labelWidth: 60,
  displayField: 'text',
  valueField: 'id',
  queryMode: 'local',
  renderTo: Ext.getBody()
});

動作するフィドルはhttps://fiddle.sencha.com/#fiddle/dipにあります。

于 2014-11-18T14:50:37.070 に答える