2

我正在尝试使用 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"
     }
]}

谢谢

4

3 回答 3

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]”一样转换为相同的字符串。这就是为什么。

于 2013-06-22T00:10:34.413 回答
0

jsonResponse 它是一个对象/数组还是字符串?

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

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

Sencha:JSON 编码

于 2013-06-17T09:57:34.943 回答
0

您能否尝试使用loadRawData 而不是loadData

于 2014-03-18T04:25:40.577 回答