2

I have a model defined as BUS having fields tyre (string), color(string) , company(string).In the main panel trying to read the data one by a ajax and other by some webservice call.Both of this needs to be displayed on the same GRID.

In the store i am creating a array of records which has two arrays one prepared by ajax call and the other prepared by webservice data.I call a method and get the data from webservice and push it to the main records array which does have the data but the type of object it stores is different.

When checked using chrome dev tools it seems to me that the one prepared from ajax are equivalent to model and the other one are just object having some fields.The below have model:function which points to the model defined.

data:Object > this have values exactly like my webservice array object.
dirty:false
editing:false
events:Object
id:"travel.data.model.BUS-ext-record-1613"
index:2
internalId:"ext-record-1613"
modified:Object
phantom:true
raw:Object
store:m

the one which i get from webservice is like normal Object in a array which i am basically combining and trying to show on GRID but the GRID display only the above type of object.

data : Object > see this object does not have those other properties
tyre: "eight"
color: "blue"

Do I need to convert it to model type before i push into the main array?

3
  • In simple words how to map my Array of Objects to Array of Model Objects and add to my store eventually Commented Aug 14, 2017 at 17:55
  • can someone help please? Commented Aug 15, 2017 at 11:06
  • store.loadFromRaw ? Commented Aug 15, 2017 at 17:43

1 Answer 1

2

you can loop through array of normal objects and use Ext.create() to create model records using the data in normal objects.

somewhat like this.

var modelObjectArray = [];

Ext.Array.each(normalObjectArray, function(normalObject, index, normalObjectArrayItSelf) {
    var modelObject = Ext.create('Complete.Model.Name', normalObject);
    modelObjectArray.push(modelObject);
});

This way you'll get an array of objects that are model records

Sign up to request clarification or add additional context in comments.

7 Comments

suppose i have a array of normal Object NorObj now within the function(normalObject > what should i use? is this the type?
@NeverGiveUp161 By normalObject I meant plain javascript object. for example; var obj = { tyre: "eight", color: "blue" }; you can name it anything you like.
Ok, i have tweaked the iteration part.The thing which i was unaware was Ext.create('Complete.Model.Name', normalObject); and it helped.The only issue am facing is the model records have data inside it and the one which am creating with Ext.create have one data object inside it which in turn which have all the fields of the model object + one more data object which have the actual values.
I am expecting it to be the transformed model object should have a data object which should map the data to model fields not like my one which have data object inside that one more data object which have all the values along with the model fields. Thanks for the help
if your actual data to be mapped to the model is in the data field, then you can try passing normalObject.data instead of normalObject to the create method. This will cut off the data object one level down.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.