I have a template with the divs #entries
and #movies
In my #entries
div I show the models of my movie collection. In my #movies
div I show the results of a searchquery. (The naming of elements is quite bad, I agree).
In the view which renders the template I have the following events,
events: ->
"click li": "addEntry"
"click .remove": "destroyEntry"
addEntry: (e) ->
movie_title = $(e.target).text()
@collection.create title: movie_title
appendEntry: (entry) ->
view = new Movieseat.Views.Entry(model: entry)
$('#entries').append(view.render().el)
destroyEntry: (e) ->
thisid = @$(e.currentTarget).closest('div').data('id')
@collection.get(thisid).destroy()
The li element gets rendered in the #movies
div. This way I can click on the results from a different view and add them into a other collection. This works, but there's a problem.
In the same view I have this,
initialize: ->
@collection.on('change', @render, this)
@collection.on('add', @appendEntry, this)
@collection.on('destroy', @render, this)
return
The problem is that when the collection changes (like when I add or remove a movie from it) it rerenders the template. This means it rerenders the #entries
and #movies
div. But now it just renders a empty #movies
div (without the searchquery collection).
So I was wondering if it's possible to only render a part of a template. In this case I would like to only rerender the #entries
div and just leave the #movies
div alone.