Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone: Lost reference to actual view?
    primarykey
    data
    text
    <p>I'm new to Backbone (and Marionette), and trying to write a pretty simple app using both. The app has a menu of "groups" on the left nav, and a list of "entries" on the main right div. Every time a Group menu item is clicked, I filter the entries with the group ID and show them, when hide all others. </p> <p>Here is the Entry Item view (all scripts are in CoffeeScript btw):</p> <pre><code>class EntryItemView extends Backbone.Marionette.ItemView tagName: 'tr' template: _.template $('#entryItemTemplate').html() render: -&gt; @$el.html @template(@model.toJSON()) show: -&gt; @$el.show() hide: -&gt; @$el.hide() </code></pre> <p>Here is the Entry List view, extending Marionette's CollectionView:</p> <pre><code>class EntryListView extends Backbone.Marionette.CollectionView itemView: EntryItemView el: '#main tbody' </code></pre> <p>This is the AppRouter, pretty much straightforwad:</p> <pre><code>class AppRouter extends Backbone.Router routes: 'group/:id' : 'showGroup' router = new AppRouter() router.on 'route:showGroup', (id) -&gt; _.each entryViews, (view) -&gt; if view.model.get('group_id') is parseInt(id) view.show() else view.hide() </code></pre> <p>(The <code>entryViews</code> variable is a simple global array to store all EntryItemView instances).</p> <p>With this approach, navigating the app to /group/:id indeed invokes the show() and hide() method of each EntryItemView object. The problem is, looks like the reference between this object and the actual HTML doesn't exist, so the actual element <code>&lt;tr&gt;</code> doesn't show or hide. </p> <p>Can you guys point out what I'm doing wrong here? Thanks in advance.</p>
    singulars
    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.
    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