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!

CD..
  • 72,281
  • 25
  • 154
  • 163
liu peng
  • 95
  • 1
  • 2
  • 10

4 Answers4

1

Wait for the server response :

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

Details about the callback function here.

1

I tried, Following will do the trick:

user.load({
    scope: this,

    callback: function(records, operation, success) {
    user.each(function(record) {
        console.log(record.get('name'));
    });
    }
});
user650749
  • 182
  • 2
  • 13
0

I came across the similar issue with following codes: `

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!

`

Not sure whether the data property was populated properly or not.

I believe you have the same problem because getAt will retrieve records from data property .

user650749
  • 182
  • 2
  • 13
-1

I think you need to mention the url inside the proxy or you need to use the setProxy() method on the store to set the URL. With out doing this, the values might not get returned. Check the sencha docs for further information.

Aashray
  • 2,753
  • 16
  • 22