sagar
sagar

Reputation: 1432

ExtJs JSONStore loaddata method loading only single record

I am trying to load data in JSONStore using loadData method, but it is only loading single record in store. Here is code snippet

var myRecord = Ext.data.Record.create([
    {
        name: 'Rid',
        type: 'string',
        mapping: 'id.value'
    }, {
        name: 'accountId',
        type: 'string',
        mapping: 'accountId.value'
    }, {
        name: 'nickName',
        type: 'string'
    }
]);

var myStore = new Ext.data.JsonStore({
        storeId: 'storeID',
        fields: myRecord,           
        root: 'recipientResponse',
        autoLoad: false

});

myStore.loadData(jsonResponse,true);

Here is sample JSON response that I am passing to loadData method

{ recipientResponse: [
    {
        "id":{
            "value":"58144340bedf4a328669c98b29446b6b"
        },
        "locked":null,
        "accountId":{
            "type":null,
            "value":"1122334455"
        },
        "nickName":"Dad",
        "customerId":{
            "value":"partialpay7"
        },
        "accountType":"CHECKING", 
        "emailAddress":"[email protected]",
        "person":null,
        "deleted":null,
        "txPasscode":"Cho"
     },
     {
        "id":{
            "value":"5fb1e201a939433faea6c39e33caef78"
        },
        "locked":null,
        "accountId":{
            "type":null,
            "value":"6655223311"
        },
        "nickName":"Jane Doe",
        "customerId":{
            "value":"partialpay7"
        },
        "accountType":"CHECKING",
        "emailAddress":"[email protected]",
        "person":null,
        "deleted":null,
        "txPasscode":"Cho"
     },
     {
        "id":{
             "value":"a24b32fd180e4886b1f562d9a3b2f0ce"
        },
        "locked":null,
        "accountId":{
            "type":null,
            "value":"998877665544"
        },
        "nickName":"Sam Jones",
        "customerId":{
            "value":"partialpay7"
        },
        "accountType":"CHECKING",
        "emailAddress":"[email protected]",
        "person":null,
        "deleted":null,
        "txPasscode":"Cho"
     }
]}

Thanks

Upvotes: 2

Views: 3915

Answers (3)

Hosang Jeon
Hosang Jeon

Reputation: 1423

Could you please try to use loadRawData NOT loadData?

Upvotes: 0

rixo
rixo

Reputation: 25031

You must configure the idProperty.

var myStore = new Ext.data.JsonStore({
    storeId: 'storeID',
    fields: myRecord,           
    root: 'recipientResponse',
    autoLoad: false,
    idProperty: 'Rid'
});

If you don't, it defaults to 'id', so the json reader use your whole objects {id: ...} as id. In the end, these ids are used as keys in the data collection, and they all cast to the same string like "[object Object]". Here's why.

Upvotes: 6

mfruizs
mfruizs

Reputation: 770

jsonResponse it's a Object/Array or String ?

It's a String, try using:

myStore.loadData(Ext.JSON.encode(jsonResponse),true);

Sencha: JSON Encode

Upvotes: 0

Related Questions