Note that there are some explanatory texts on larger screens.

plurals
  1. POHow To Change Backbone Dynamic URL with Backbone Events/Vent?
    primarykey
    data
    text
    <p><strong>Edited This Below</strong></p> <p>In this image below I have two main regions.</p> <p>One for the user list on the left: <strong>allusersRegion</strong></p> <p>And another for the the right side where a layout is displayed, which contains unique attributes to the user that was clicked in the <strong>allusersRegion</strong> and a list of articles by the user: middleCoreRegion</p> <p>**If you noticed the middleCoreRegion is showing all articles by all users..This is wrong and I am trying to show all articles of the individual user (in this case. "kev")</p> <p><img src="https://i.stack.imgur.com/ls7XB.jpg" alt="enter image description here"></p> <p>I tried to see if my problem was with my JSON api (served via node/rest/mongoose) or with my underscore templates, but if it displays both list then I suppose I need to filter from inside backbone.</p> <p>At first I tried using a Marionette.vent to simply change the url, but somhow I can't get the _id name into the url: function(), it says undefined...</p> <pre><code>var someuser = this.model.get("_id"); myApp.vent.trigger("showarticles", someuser); </code></pre> <p>I add a listener in the backbone collection on the same page:</p> <pre><code>myApp.vent.on("showarticles", someuser); </code></pre> <p>**The Edit (A Different Way of Doing this) Here is my code</p> <pre><code>var usertab = Poplive.module('usertab', { startWithParent: true, }); usertab.addInitializer(function() { User = Backbone.Model.extend({}); UniqueArticle = Backbone.Model.extend({}); //Collections Users = Backbone.Collection.extend({ model: User, url: '/api/user2' }); UniqueArticles = Backbone.Collection.extend({ model: UniqueArticle, url: '/api/survey' }); //Layout var VisitingLayoutView = Backbone.Marionette.Layout.extend({ template: "#visiting-layout", regions: { firstRegion: "#listone", secondRegion: "#listtwo", thirdRegion: "#listthree", playRegion: "#playhere", articlesRegion: "#articleshere" } }); AllUserView = Backbone.Marionette.ItemView.extend({ template: "#tab-alluser-template", tagName: 'li', events: { "click #openprofile" : "OpenProfile" }, OpenProfile: function(){ console.log("Profile is open for " + this.model.get("username")); var modelo = this.model.get("_id"); var vlv = new VisitingLayoutView({model: this.model}); Poplive.middleCoreRegion.show(vlv); var ua = new UniqueArticles(); var uacoll = new UniqueArticlesView({collection: ua}); vlv.articlesRegion.show(uacoll); } }) //ItemViews UniqueArticleView = Backbone.Marionette.ItemView.extend({ template: "#unique-article-template" }); //CollectionViews AllUsersView = Backbone.Marionette.CompositeView.extend({ template: "#tab-allusers-template", itemView: AllUserView }); UniqueArticlesView = Backbone.Marionette.CollectionView.extend({ template: "#unique-articles-template", itemView: UniqueArticleView }); //Render Views var alluserview = new AllUserView(); var allusersview = new AllUsersView(); //Fetch Collections var theusers = new Users(); theusers.fetch(); var userscoll = new AllUsersView({collection: theusers}); Poplive.allusersRegion.show(userscoll); }); </code></pre>
    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