Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone.js: Best way to clear a all views
    primarykey
    data
    text
    <p>I am using Backbone.js to render a list of items (email recipients) that have different status, eg. confirmed, pending and so on. After the list is rendered there are options for user to filter them so the user can list all recipients, or only confirmed recipients and so on. The items (recipients) are naturally stored in a collection..</p> <p>My approach is to on a filter event:</p> <ol> <li>Clear all item's view's</li> <li>From the app view call a filterOnStatus function in the collection that return all models and adds them to the view.</li> </ol> <p>Step 2 works fine. But what's the best way to clear all items on a collection's view's.</p> <p>In the Todo example application (<a href="http://documentcloud.github.com/backbone/examples/todos/index.html" rel="nofollow">http://documentcloud.github.com/backbone/examples/todos/index.html</a>) they do something similar. In the app view the following code is used to clear all completed items from the list. </p> <pre><code>clearCompleted: function() { _.each(Todos.done(), function(todo){ todo.destroy(); }); return false; }, </code></pre> <p>The difference here is that they do this by removing the actual model. And that model's view listens for the destroy event which them removes the view.</p> <p>I want to keep the model. </p> <p>What's the best way to solve this. Do I in the models need to stored a reference to its views and then iterate over the models and remove the views?</p> <p>Is there a better approach if I want to filter on attributes in the models?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload