0

I am using ExtJs 4.1.

I have a Store like this:

var predictTargetStore = new Ext.create('Ext.data.Store',{
    autoLoad : false,
    fields: ['label','value'],
    proxy : {
        type : 'ajax',
        reader : {
            type : 'json',
            root : 'predictTargetList'
        }
    }
});

I will do predictTargetStore.load({url : 'getPredictTargetList.action'}) some time later.after I have done this,the combobox which used predictTargetStore will have choices. but when I try to get one item from the store,I failed.I do like this:

predictTargetStore.load({
    url : 'getPredictTargetList.action'
});
var value = predictTargetStore.getAt(0).get('value');

I find predictTargetStore.getAt(0) is null and predictTargetStore.getCount() is 0. so how can I get one item of the store? thank you very much!

4

4 回答 4

1

我试过了,下面会做的伎俩:

user.load({
    scope: this,

    callback: function(records, operation, success) {
    user.each(function(record) {
        console.log(record.get('name'));
    });
    }
});
于 2013-03-01T01:42:11.720 回答
1

等待服务器响应:

predictTargetStore.load({
    url : 'getPredictTargetList.action',
    callback: function () {
        var value = predictTargetStore.getAt(0).get('value');
    }
});

有关callback功能的详细信息,请点击此处

于 2013-02-28T12:59:48.340 回答
0

我遇到了以下代码的类似问题:`

Ext.define('MyApp.model.EOrder.Model.TestRequest', {
    extend : 'Ext.data.Model',
    fields : [{
            name : 'testId',
            type : 'int'
        }, {
            name : 'testCode'
        }, {
            name : 'testName'
        }, {
            name : 'price',
            type : 'float'
        }
    ]
});

var testStagingStore = Ext.create('Ext.data.Store', {
        model : 'MyApp.model.EOrder.Model.TestRequest',
        storeId : 'StagingTestRequest',
        autoLoad : false,
        proxy : {
            type : 'ajax',
            url : 'LOINC.json',
            reader : {
                type : 'json',
                root : 'TestRequest'
            }
        },
        listeners : {
            load : function () {
                loadedCount = this.data.getCount();
                console.log('json file loaded. processed records:' + loadedCount);
            }
        }
    });

testStagingStore.load();

console.log(testStagingStore.data.items);    // in chrome "network" console, I know my json file was loaded successfully. But here I get nothing!

`

不确定数据属性是否正确填充。

我相信您也有同样的问题,因为 getAt 将从 data property 检索记录。

于 2013-02-28T15:12:41.590 回答
-1

我认为您需要提及url代理内部或者您需要使用setProxy()商店上的方法来设置URL。如果不这样做,这些值可能不会被返回。查看 sencha 文档以获取更多信息。

于 2013-02-28T09:38:28.937 回答