0
votes

I have an Ember Route class defined as below;

export default Ember.Route.extend({
    model: function() {
        var compObj = {};
        compObj.gridPara = this.get('gridPara');
        return compObj;
    },
    gridPara: function() {
        var self = this;
        var returnObj = {};
        returnObj.url = '/myService';
        // setting some other returnObj attributes
        var summaryObj = {
            total: {
                label: "Total 1",
                value: "100"
            },
            additional: [{
                label: 'Label 2',
                value: 'val2'
            }, {
                label: 'Label 3',
                value: 'val3'
            }]
        };
        returnObj.summary = summaryObj;
        return returnObj;
    },
    actions: {
        dataLoaded: function(resp) {
            // Here I get the service response and want to set (or overwrite) the summaryObj values
            this.get('gridParams').summary.total.value = resp.numRows;          
        }
    }
});

My template looks like

{{my-grid params=this.gridPara dataLoaded="dataLoaded"}}

Now I want to set the "summary" on returnObj I have verified that I get "resp" inside dataLoaded callback.

But I get the following error when trying to do

this.get('gridParams').summary.total.value = resp.numRows;      

Uncaught Error: Assertion Failed: You must use Ember.set() to set the value property (of [object Object]) to 100.

Also how do I set/push for "additional" array inside summaryObj

3

3 Answers

1
votes

As the error states, you must use set to the the value (Im assuming you have gridParams defined somewhere?):

this.set('gridParams.summary.total.value', resp.numRows);

In order to push a new object, try this:

var additional = this.get('gridParams.additional');
additional.push({label: ..., value: ....});
this.set('gridParams.additional', additional);
0
votes

not 100% sure, but give it a try:

  • Watch out the property names. I suppose it's a wording error to declare 'gridPara' and trying to get 'gridParams'
  • You should retrieve the value like this
    this.get('gridParams.summary.total.value')
  • What you are trying with the last sentence is a setting, but like it was plain JS. In Ember you should do it this.set('gridParams.summary.total.value',resp.numRows)
0
votes

Just adding to @Remi answers ,the best practice would be to use

Ember.set('gridParams.summary.total.value', resp.numRows);

To answer the question in your comment Say you want to update additional array at index i.Just do

var updateItem = additional[i];
Ember.set(updateItem.propertyname,newValue)
//Here propertyname would be the property you want to update and new Value is the new value which you want to set to that property