Answer the question
In order to leave comments, you need to log in
How to set action in itemController?
Hi all!
I decided to take a look at emberjs for myself. The framework is actively moving towards 2.0 and even those recent examples that are on the network no longer work with the current version without finishing. The question is banal, there is a controller that is inherited from ArrayController, in its template I display elements, the controller itself:
App.ListController = Ember.ArrayController.extend({
itemController: 'item',
});
{{#each item in model}}
<div>
<h1>{{item.name}}</h1>
<a {{action "removeItem"}}>remove</a>
</div>
{{/each}}
App.ItemController = Ember.Controller.extend({
actions: {
removeItem: function() {
var item = this.get('model');
item.destroyRecord();
}
}
});
removeList: function() {
console.log('???');
var item = this.get('model');
console.log(item);
}
Answer the question
In order to leave comments, you need to log in
Hello. Welcome to the Ember community.
Why is there an itemController at all? I would do like this:
{{#each item in model}}
<div>
<h1>{{item.name}}</h1>
<a {{action "removeItem" item}}>remove</a>
</div>
{{/each}}
App.ListController = Ember.Controller.extend({
actions: {
removeItem: function(model) {
model.destroyRecord();
}
}
});
App.ItemListComponent = Ember.Component.extend({
item: null,
actions: {
removeItem: function() {
var item = this.get('item');
item.destroyRecord();
}
}
});
{{#each item in model}}
{{item-list item=item}} //извиняюсь за тавтологию
{{/each}}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question