Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS creating record from existing store

I have created an ext store like so:

var store = new Ext.data.JsonStore({
       root: 'vars',
       fields: [{ name: 'rec_id', mapping: 'rec' }, { name: 'identity', mapping: 'id'}]
});

This works alright when I add data to the store via loadData(); and some json which looks like:

{ vars : {rec: '1', id:'John'} }

My problem is that if I use add(); to get this record into the store I have to first create it as an Ext.data.Record object.

I do this as pointed out here: https://stackoverflow.com/a/7828701/1749630 and it works ok.

The issue I have is that the records are entered with their mapped parameters rather than the ones I set. I.e, 'rec_id' becomes 'rec' and 'identity' becomes 'id'.

What am I doing wrong here?

like image 318
aaron-bond Avatar asked Dec 06 '25 02:12

aaron-bond


1 Answers

You need to do the mapping manually, something like this:

var myNewRecord = new store.recordType({
    rec_id: vars.rec,
    identity: vars.id
});

store.add(myNewRecord);
like image 152
Matthew Strawbridge Avatar answered Dec 07 '25 16:12

Matthew Strawbridge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!