I'm having a hard time finding an answer to this, so perhaps I'm doing it all wrong. I have a collection view with an item view class. Each item has a delete button, which refers to the action "removeItem." This does remove the item, but I need to refer back to the collection view content in order to post the updated array with an API call.
App.WatchlistTilesView.Collection = Ember.CollectionView.extend({
tagName: "ul",
itemViewClass: Ember.View.extend({
attributeBindings: "role",
role: "tile",
classNames: ["tile"],
removeItem: function() {
this.remove();
},
templateStock: Ember.Handlebars.compile("
<button {{action removeItem}}>Delete</button>
...
"),
})
});
EDIT:
I found the answer to this particular problem. There was a property on the collection view that needed to be accessed by the item class. I was able to access it with this.get("parentView"). Also, I had to add the view as the target for the removeItem action.
It looks something like this:
App.WatchlistTilesView.Collection = Ember.CollectionView.extend({
tagName: "ul",
itemViewClass: Ember.View.extend({
attributeBindings: "role",
role: "tile",
classNames: ["tile"],
watchlistBinding: "parentView.watchlist"
removeItem: ->
@remove()
watchlist = @get("watchlist")
@get("controller").removeSymbol(@content, watchlist)
templateStock: Ember.Handlebars.compile("
<button {{action removeItem target="view"}}>Delete</button>
...
"),
})
});
App.WatchlistTilesController = Ember.Controller.extend({
account: null,
watchlists: null,
removeSymbol: function(entry, watchlist) {
watchlist.entries.removeObject(entry);
return WatchlistService.edit(this.account, watchlist);
}
});