Search code examples
javascriptextjssencha-touch-2

how sencha get string from records


here is my code. i want get "data" and "earn" string type from the records.

storeId.load({
        callback: function(records, operation, success){
            console.log(records);
            //Ext.getCmp('datalabel').setData({test: 'Foo'});                
        }
    });

in the chrome console:

0: Ext.apply.create.f
_data: Object    
data: Object
data: "300000"---------------i want
earn: "100000"---------------i want
id: "ext-record-2"
__proto__: Object
id: "ext-record-2"
internalId: "ext-record-2"
modified: Object
phantom: true
raw: Object
stores: Array[1]
__proto__: Object
length: 1
__proto__: Array[0]

Solution

  • Iterate over the records or get a record by index:

    storeId.load({
        callback: function(records, operation, success){
            Ext.each(records, function(record) {
                console.log(record.get('data'));
                console.log(record.get('earn'));
            });
    
            // or
    
            var recordByIndex = records[0];
            console.log(recordByIndex.get('data'));
            console.log(recordByIndex.get('earn'));
        }
    });