Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my opinion, the view you're talking about should not know about its distant parents or cousins but rather should trigger an event "I have new content" and then the interested views can act upon this the way they want.</p> <p>That being said there is a difference between a view and its html representation(s), you could design your app so that you get 2 places in the html where you put ".new-content-holder" and pass this selector as the el of your view upon creation. Then the 2 places will be updated at the same time without you explicitly programming it. I sometimes use this technique for example when I want a paginator for a long list to be displayed over and under the list.</p> <p>Some html :</p> <pre><code>&lt;div class="content"&gt; &lt;p&gt;Recent comments&lt;/&gt; &lt;ul class="new-content-holder"&gt;&lt;/ul&gt; &lt;/div&gt; &lt;div class="chat-room"&gt; Live feed &lt;ul class="new-content-holder"&gt; &lt;li&gt;a chat message&lt;/li&gt; &lt;li&gt;another chat message&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>And a view</p> <pre><code>.... var MessageView = Backbone.View.extend({ template: _.template('&lt;li class="chat-message"&gt;&lt;%= message %&gt;&lt;/li&gt;'), prependData: function(data){ this.$el.prepend(this.template(data)) }, onMessage: function(message) { this.prependData({message: message.data}) } }); .... //And in a super controller of sorts : var messageView = new MessageView(el: '.new-message-holder') </code></pre> <p>Again, this is not a very good separation of concerns...but I hope that helps.</p>
    singulars
    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.
    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