0

我有和 extjs 任务在 Ext.TaskManager 中运行,它每 5 秒重新加载我的 ext 存储。每次调用任务时,我都会更新 currentIndex 变量,该变量在我的组合框中保存当前选定的索引(值)。我得到的问题是,在某些情况下,不是获取数字 currentIndex 而是获取值 [object Object]。我真的不知道为什么会这样。这是我的示例代码:

// combo store
var myStore = Ext.create('Ext.data.Store', {
    id: store_id,
    fields: ['label', 'value', 'type'],
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url: '/url/to/controller',
        reader: {
            type: 'json',
            root: 'MyModel'
        }
    }
}),

 createWindow = function() {
    var myComboBox = Ext.create('Ext.form.field.ComboBox', {
        flex: 3,
        editable: false,
        value: 'Select option',
        displayField: 'label',
        valueField: 'value',
        store: myStore,
        cls: 'comboCssClass',
        id: ComboBoxId,
        listeners: {
            'select': function(combo, row, index) {
                var rowData = row[0].data;
                currentIndex = this.getValue();
             }
        }
   };

   return newWindow = Ext.create('Ext.widget.window',{
          // window settings
          items:[myComboBox ]
   });
},

reloadStoretask = {
    run: function(){
          myStore.load();

          // here is where in some cases I get [object Object] instead of number 
          // And I think the object is Ext.data.store.ImplicitModel or it was alike. 
          // so currentIndex = [object Object] in some cases
          record = myStore.getAt(currentIndex).data;
    },
    interval: 5000
}

如何解决这个问题或我做错了什么?

4

1 回答 1

1

may be you are loading your store twice, you configured your store with autoload:true then you call reloadStoretask function to reload the store.

于 2014-04-30T16:17:27.723 回答