Using Ember, I have an object in my controller that looks like this:
ItemDetails: {
Retrieved: '2016-07-09',
User: 'someuser',
Items: [
{
Name: 'Item',
Price: 'value'
},
// snip
]
}
This is set in the controller init using this.set('ItemDetails', jsonObject).
The template is rendered as
{{#each ItemDetails.Items as |Item|}}
{{Item.Name}}
{{Item.Price}}
<input type="button" {{action "Remove" Item.Name }} value="Remove" class="btn btn-primary" />
{{/each}}
The action for Remove is defined thusly:
Remove: function(itemName) {
var details = this.get('ItemDetails');
var index = -1;
for(var i = 0; i < details.Facets.length; i++) {
if(details.Items[i].Name == itemName) {
index = i;
break;
}
}
if(index > -1) {
details.Items.splice(index, 1)
this.set('Search', details);
}
}
Now using the Chrome debugger I can confirm that the array is correct and the correct item is being removed. Subsequent calls in also show the array internally looks like it should.
However, the template does not reflect this change, i.e. the Item is still shown along with it's remove button. What am I doing wrong that the template is not being updated?
Aucun commentaire:
Enregistrer un commentaire