I'm working on Ember 2.13.0
The Ember.js doco for controllers says "The controller receives a single property from the Route – model – which is the return value of the Route's model() method." .
I'm not clear how I can access this data.
I have a route that looks like this :
export default Ember.Route.extend({
model: function() {
return this.store.findAll('costcentrehierarchyfortree');
}
});
And a controller that looks like this :
export default Ember.Controller.extend({
data: function() {
var arrJSTreeElements = this.model.map(obj =>{
/*
* This is the type of structure that needs to be output
*
[
{ "id" : "ajson1", "parent" : "#", "text" : "Simple root node" },
{ "id" : "ajson2", "parent" : "#", "text" : "Root node 2" },
{ "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" },
{ "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" },
]
*/
var rObj = {};
rObj['id'] = obj.cchcceidchild;
if (obj.cchcceidparent === obj.cchcceidchild)
{
//This is the top of the tree
rObj['parent'] = "#";
}
else
{
rObj['parent'] = obj.cchcceidparent;
}
rObj['text'] = obj.ccidescriptionchild;
return rObj;
});
return arrJSTreeElements ;
}
});
But when I visit the route in question I get a console error
Cannot read property 'map' of undefined
So I guess that using this.model
to access the data returned from the route's model() method is not the way to go ... so what am I doing wrong ?
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire