ExtJs JSONStore loaddata方法只加载单个记录

时间:2013-06-17 08:40:41

标签: javascript extjs

我正在尝试使用loadData方法在JSONStore中加载数据,但它只在商店中加载单个记录。这是代码段

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);

以下是我传递给loadData方法的示例JSON响应

{ recipientResponse: [
    {
        "id":{
            "value":"58144340bedf4a328669c98b29446b6b"
        },
        "locked":null,
        "accountId":{
            "type":null,
            "value":"1122334455"
        },
        "nickName":"Dad",
        "customerId":{
            "value":"partialpay7"
        },
        "accountType":"CHECKING", 
        "emailAddress":"blah@blah.com",
        "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":"blah@blah.com",
        "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":"blah@blah.com",
        "person":null,
        "deleted":null,
        "txPasscode":"Cho"
     }
]}

由于

3 个答案:

答案 0 :(得分:6)

您必须配置idProperty

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

如果不这样做,则默认为'id',因此json阅读器将您的整个对象{id: ...}用作id。最后,这些id用作数据集合中的键,它们都转换为相同的字符串,如“[object Object]”。这就是原因。

答案 1 :(得分:0)

jsonResponse它是一个Object / Array还是String?

这是一个字符串,尝试使用:

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

Sencha:JSON Encode

答案 2 :(得分:0)

您能否尝试使用 loadRawData NOT loadData