I want to know what is the proper way to load data into store. I have my router defined as:
this.resource('analyticsTemplates', { path: 'templates' });
this.resource('analyticsTemplate', { path: 'templates/:analytics_template_id' });
and for my 'analyticsTemplates' route, I have defined a handlebar template that lists all templates in a table and an add button which opens up a modal box with a form which when submitted should add a new record to the store and update my table. Now my form uses file input fields so I didn't use
this.get('model').save()
which properly syncs the store. Instead when the form submits, it posts the form to an hidden iframe and this iframe's body content is then populated by json data that represents the currently added record. The return data looks something like this :
{
"analyticsTemplate": {
"id": 6,
"name": "deee",
"description": "asdasdasd",
"csFileName": "commandScript.txt",
"csLastUpdatedBy": "Deewendra Shrestha",
"csLastUpdated": "2013-10-22T18:00:54Z",
"dateCreated": "2013-10-22T18:00:54Z",
"lastUpdated": "2013-10-22T18:00:54Z",
"createdBy": "Deewendra Shrestha",
"lastUpdatedBy": "Deewendra Shrestha",
"parameters": {
"homeDir": {
"category": "global",
"description": "Where is the analytics folder",
"name": "homeDir",
"value": "Q:/Reckitt Benckiser/2013/RB_Steroid/Analytics/IntergerateTest_DONOTUSE"
},
"historyDir": {
"category": "global",
"description": "Where R image will be saved",
"name": "historyDir",
"value": "Rhistory"
},
"Sourcefolder": {
"category": "type 1",
"description": "Where are source codes and functions are saved",
"name": "Sourcefolder",
"value": "J:/_MRO/Analytics/Analytics_R_Source_Scripts"
},
"resultsDir": {
"category": "global",
"description": "Where are results stored",
"name": "resultsDir",
"value": "results"
},
"dataDir": {
"category": "opt",
"description": "Where is raw csv stored",
"name": "dataDir",
"value": "Export"
},
"testParam": {
"category": "global",
"description": "some long sentence repeated multiple times. some long sentence repeated multiple times. some long sentence repeated multiple times.",
"name": "testParam",
"value": "some long sentence repeated multiple times. some long sentence repeated multiple times.some long sentence repeated multiple times."
}
}
}
}
I tried two things in my controller :
this.get('store').push('analyticsTemplate',jsonData["analyticsTempalte"]);
also :
var newRecord = this.get('store').createRecord('analyticsTemplate');
for(var key in jsonData["analyticsTemplate"]){
o.set(key,jsonData["analyticsTemplate"][key]);
}
Using any one of the method above I could see the new record listed in the table but when I click on the record to drill down to "analyticsTemplate" route(similar to going from posts->post), I get js error on :
parameters.forEach(function (parameter) {
discreteCategories[parameter.get('category')] = 1;
});
I have defined a DS.transform to transform parameters into ArrayProxy and I think this transformation is not getting executed when I load the record as I have done and hence the child route has no idea how to deal with parameters. So how can I apply transformation in this case?
I wish I could just apply:
this.get('model').reload()
but it seems like this works in ObjectController context and not for ArrayController. Any ideas/alternatives friends?