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
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
Share edited Jun 17, 2013 at 8:55 BeNdErR 17.9k21 gold badges77 silver badges106 bronze badges asked Jun 17, 2013 at 8:40 sagarsagar 1,4321 gold badge13 silver badges19 bronze badges 6- is the problem that only the last record shows up in the end ? seems that having {value:string} as the key for the record requires slightly more work, but trying to make sure I got the problem down. – Abraham Adam Commented Jun 27, 2013 at 9:31
- what ExtJS version do you use? – Geo Commented Jun 28, 2013 at 19:31
- @AbrahamAdam - Yes always last record shows up in the store – sagar Commented Jul 15, 2013 at 0:19
- The reason I am responding this late is since I need to get this done soon, I dropped idea of loading this in store and used JSON object as is. But loading it in store would have helped me. I would still like to know root cause so that I can use this is future. – sagar Commented Jul 15, 2013 at 0:21
-
@sagar Does that mean that setting
idProperty: 'Rid'
didn't help? I had made some tests with your code as a base and got it working, so I was pretty sure about my answer... – rixo Commented Jul 29, 2013 at 6:55
3 Answers
Reset to default 6 +25You 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.
jsonResponse it's a Object/Array or String ?
It's a String, try using:
myStore.loadData(Ext.JSON.encode(jsonResponse),true);
Sencha: JSON Encode
Could you please try to use loadRawData NOT loadData?