mardi 27 janvier 2015

Load data from ember-data in view template

I want to load a grid with data from the data model. The data in the model is defined as follows:



myApp.Unit = DS.Model.extend({
active: DS.attr('boolean'),
allowdecimals: DS.attr('boolean'),
name: DS.attr('string'),
count: DS.attr('number'),
});


In the route I am loading 3 records and returning the data to the controller:



myApp.EunitsRoute = Ember.Route.extend({
model: function() {
this.store.push('unit', {
id: 1,
active: true,
allowdecimals: true,
name: "Pint",
count: 4
});
this.store.push('unit', {
id: 2,
active: false,
allowdecimals: true,
name: "Each",
count: 8
});
this.store.push('unit', {
id: 3,
active: false,
allowdecimals: false,
name: "Half",
count: 6
});
return this.store.all('Unit');
},
setupController: function(controller, model) {
this._super(controller, model);
controller.set('units', model);
},
actions: {
editunit: function(value,datafield,id,oldvalue) {
var self = this;
var data = {value: value,datafield: datafield,id: id,oldvalue: oldvalue};
$.post('ajax_handler/updateunit', data)
.done(function(data) {
$("#eunits_grid").jqxGrid('updatebounddata');
});
}
}
});


In the view, I am trying to load the grid with the object returned from the router but doesn't work. I think I have to reformat the data.



UnitsView = Ember.View.extend({
didInsertElement: function() {
var controller = this.get('controller');
var source10 = {
datatype: "array",
datafields: [
{ name: 'id' },
{ name: 'name' },
{ name: 'allowdecimals' },
{ name: 'active' },
{ name: 'count' }
],
localdata: controller.get('units').toArray()

};




Aucun commentaire:

Enregistrer un commentaire