backbone.js-collections

Bind a view to collections in backbone.js

|▌冷眼眸甩不掉的悲伤 提交于 2020-03-22 08:51:10
问题 I'm semi-new to backbone. I'm trying to bind a collection to a view so that when a new model is added to a collection, the view is updated. I think when you do this with models you can bind to the model's change event. But how do you do the same with collections? App.Views.Hotels = Backbone.View.extend({ tagName: 'ul', render: function() { this.collection.each(this.addOne, this); var floorplanView = new App.Views.Floorplans({collection:floorplanCollection}); $('.floorplans').html

backbone.js adding model to collection adds to all models in collection

随声附和 提交于 2020-01-14 12:12:30
问题 Playing around with backbone.js, so far I've created models and collections for a deck of cards and two players. The problem is when I try move a card from the deck and add it to the player's hand the card gets added to all players hands. Here's my offending code, hopefully a boffin will spot the mistake straight away: //the first card goes to player1 var topCard = deck.at(0); //A of hearts deck.remove(topCard); var hand = players.at(0).get("hand"); hand.add(topCard); //the second card goes

Why doesn't Backbone Collection fetch return a promise

不想你离开。 提交于 2020-01-14 10:18:08
问题 The following example code works well: Auth_controller.prototype.isLogged = function(){ //Check if the user is authenticated var getAuthStatus = this.auth_model.fetch(); return getAuthStatus; }; Auth_controller.prototype.redirect = function(fragment, args, next){ var getAuthStatus = this.isLogged(); var self = this; $.when(getAuthStatus).then(function(response){ //Do something with the response } }); This doesn't seem to work for a Collection though. When I console log the collection, I get

setting fuelux datagrid source from backbone collection

独自空忆成欢 提交于 2020-01-11 12:34:28
问题 I am trying to set the fuelux datagrid source from my backbone collection. The examples source is here on https://github.com/ExactTarget/fuelux/tree/master/sample . I tired like (function (root, factory) { if (typeof define === 'function' && define.amd) { define(factory); } else { root.sampleData = factory(); } }(this, function () { return { "geonames": new mycollection ///this will retrurn new collection array as in example }; })); And my backbone render consist following code to instatate

Loading collections into models in backbone.js

六眼飞鱼酱① 提交于 2020-01-06 15:07:29
问题 Here's the goal: I have a parent model. It is in a collection called parents . In a parent is a collection of children . So, when I instantiate the parents collection, I get the parent models, each with the collection of children in them. I've tried doing this several different ways, and I'm getting different performance. Sometimes the children don't show up at all. Sometimes, they are repeated for each iteration of the parent render loop. I'm looking for help on what the best practice is for

Search words in any order using backboneJS collection

ε祈祈猫儿з 提交于 2020-01-06 04:01:15
问题 I have code to search the typed words from the text box, Get the typed word, search it in the collection and show the result in the HTML page. In that i can search the word exactly as it is, using LIKE. (i.e) search: function(type,letters){ var pattern = new RegExp(letters,"gi"); return _(this.filter(function(data) { return pattern.test(data.get(type)); })); } If the model has, Hello Doctor Hi Sir Hello World Welcome Programmer And the user types as "Hello", it shows me Hello Doctor Hello

Wrap items in backbone collection?

拥有回忆 提交于 2019-12-25 02:40:07
问题 I keep running into some confusing solutions and unclear ways to wrap items that match into a div using backbone. I am just building a simple example for myself, and would like to nest all models in a collection that have the same attribute team , using a comparator works well in organizing the list, but for the life of me I can't find a clear solution to wrapping each so that I have more control over the list of players inside the team. There has to be a clear easy solution for a beginner

listen to a collection add/change as a model attribute of a view

半腔热情 提交于 2019-12-22 09:09:40
问题 I have a Measure View, and it has an associated Measure Model, which has two collections, RepresentationsCollection and BeatsCollection. The Measure View has nested child Representation views, each with their own representation model, and all representation models share the same attribute of a reference to the Measure View's BeatsCollection. I know that if you are listening to a change event, the collection won't respond when something is added. You are supposed to use bind. The docs aren't

How to place a collection within a model in Backbone.js?

拜拜、爱过 提交于 2019-12-21 07:14:29
问题 I would like some insight on how one would add structure a collection within a model. My simple app has teams (so a team model and collection of teams) and each team has a bunch of players(player model and player collections). So a visual structure of it is like so: Team A - Player 1 - Player 2 - Player 3 Team B - Player 1 - Player 2 and so on... How would one structure such a backbone app? Here is how I am planning it so far: 1) I would have a Team Collection, that would hold multiple teams

backbone.js collection view example using marionette template

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 10:43:33
问题 Can you please suggest me some example for showing list view through marionette template system. Basically, I have a marionette template and based on the template i am creating a table list. 回答1: To create a list of table rows with Backbone Marionette you'll need to define five things: A model for each row A collection to hold all the row models A CollectionView to iterate through the collection An ItemView to provide row-specific functionality A template for the ItemView that provides the