从JSON响应第一次加载时,Ext JS为空ItemSelector

时间:2012-05-21 13:09:55

标签: extjs extjs4 ext4 jsonstore itemselector

我正在使用extjs 4创建一个带有Itemselector的表单。我正在使用Json存储我有JSON响应的商店,如下所示:

{"items":[{"id":"12","name":"Cable"},{"id":"8","name":"Document"},{"id":"1","name":"Equipment"},{"id":"2","name":"Instrument"},     {"id":"10","name":"Isometric"},{"id":"11","name":"Joint"},{"id":"4","name":"Line"},{"id":"3","name":"LineSeg"},{"id":"5","name":"Specialty"},{"id":"6","name":"Spool"},{"id":"7","name":"Valve"},{"id":"9","name":"Weld"}]}

我的表格

Ext.require([
        'Ext.ux.form.MultiSelect',
        'Ext.ux.form.ItemSelector'
        ]);


Ext.define('MyAPP.view.directory.MyForm', {
    extend: 'Ext.form.Panel',
alias:'widget.myform',
    border: false,
    split: true,
bodyPadding: 5,
lableWidth:30,
autoScroll : true,
defaults: {
    anchor: '100%'

},
defaultType: 'textfield',
items: [
    {
xtype:'fieldset',
title: 'Commodities',
collapsible: true,
border:0,
defaultType: 'textfield',
defaults: {anchor: '100%'},
layout: 'anchor',
items :[
      {
        xtype: 'itemselector',
        name: 'commoselector',
        id:'commoselector',
        listAvailable:'',
        listSelected:'',
        fieldLabel: '',
        imagePath: 'extjs407/ux/css/images/',
        store: Ext.create('MyAPP.store.CommodityStore'),
        displayField: 'name',
        valueField: 'id',
        //value: ['9'],
        //allowBlank: false,
        msgTarget: 'under'
      }
 ]
},



 initComponent: function () {
    this.callParent(arguments);
}
});

我的商店

 Ext.define('MyAPP.store.CommodityStore', {

  extend: 'Ext.data.Store',

 constructor: function(cfg) {

 var me = this;
 cfg = cfg || {};
 me.callParent([Ext.apply({
     autoLoad: true,
     autoDestroy: true,
     storeId: 'CommodityStore',
     proxy: {
        type: 'ajax',
        url: 'getCommodityList',
        reader: {
            type: 'json',
            root: 'items'
        }
    },
    fields: [
            {name: 'id'},
            {name: 'name'}
    ]
   }, cfg)]);
  }
   });

虽然JSON是正确的,但表单创建时未加载空白存储。哪里做错了?请帮忙。提前致谢

2 个答案:

答案 0 :(得分:0)

您无需像store: Ext.create('MyAPP.store.CommodityStore'),

那样手动创建商店

你通常做的只是放store: 'CommodityStore'而ExtJs会自动完成剩下的工作。

答案 1 :(得分:0)

initComponent: function () {
var me = this;
Ext.applyIf(me, {
    listeners: {
    beforerender: {
            fn: me.onFormBeforeRender,
            scope: me
        }
   }
});

me.callParent(arguments);

},

onFormBeforeRender: function(abstractcomponent, options) {
        // where store is created globally like this var store =          Ext.create('TIP.store.CommodityStore');

store.load(function(){
    Ext.getCmp("commoselector").bindStore(store);
});
}

并在商店中自动加载:false