backbone.js-collections

Backbone collection where clause with OR condition

余生长醉 提交于 2019-12-03 09:41:10
问题 I have searched for this for quite some time but could not get a way to have a where clause with or condition. For example if I have a collection Cars and I try to do the following: Cars.where({ model: 1998, color: 'Black', make: 'Honda' }) So what the above will do is search for a car whose model is 1998 AND color is Black AND make is Honda . But I require a way to get cars which have either of the three conditions true. 回答1: Cars.filter(function(car) { return car.get("model") === 1998 ||

Backbone nested collection

爱⌒轻易说出口 提交于 2019-12-03 06:08:19
问题 I have an app in backbone that retrieve data from a server. This data are hotels and foreach hotel I have more rooms. I have divided hotel into a json and rooms inside another json like this: hotel.json [ { "id": "1", "name": "Hotel1" }, { "id": "2", "name": "Hotel2" }, { "id": "3", "name": "Hotel3" } ] rooms.json [ { "id" : "r1", "hotel_id" : "1", "name" : "Singola", "level" : "1" }, { "id" : "r1_1", "hotel_id" : "1", "name" : "Doppia", "level" : "2" }, { "id" : "r1_3", "hotel_id" : "1",

How to pluck a Backbone collection's attribute

白昼怎懂夜的黑 提交于 2019-12-03 05:21:24
I want to create an array of specific attribute values from a Backbone collection. var days = _.select( this.collection.models, function(model) { return model.attributes.type === 'session'; } ); days = _.pluck(days, 'attributes'), days = _.pluck(days, 'date'); This works, but seems inefficient. Is there a way to accomplish the same thing without having to define days three times? pluck is a convenience method that wraps map , and map is available directly on the collection, which should make this easier. assuming you are trying to get the date attribute out of your models, you can do this:

Backbone.js collection options

元气小坏坏 提交于 2019-12-03 01:37:42
问题 I have written a model/view/collection using Backbone.js. My collection uses the fetch method to load the models from a remote server. The url required for this collection needs an id like: messages/{id}. But I have found no clean way to pass options to the Collection. The backbone.js view accepts options by passing it on construction: view([options]), but the collection expects a list of models upon construction: collection([models]). What is the "cleanest" way of passing parameters/options

backbone.js collection view example using marionette template

主宰稳场 提交于 2019-12-02 22:48:17
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. seebiscuit 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 markup for each row Sample Use Case Say you have the following data: var stooges = [{ name: 'moe',

Backbone nested collection

巧了我就是萌 提交于 2019-12-02 19:36:28
I have an app in backbone that retrieve data from a server. This data are hotels and foreach hotel I have more rooms. I have divided hotel into a json and rooms inside another json like this: hotel.json [ { "id": "1", "name": "Hotel1" }, { "id": "2", "name": "Hotel2" }, { "id": "3", "name": "Hotel3" } ] rooms.json [ { "id" : "r1", "hotel_id" : "1", "name" : "Singola", "level" : "1" }, { "id" : "r1_1", "hotel_id" : "1", "name" : "Doppia", "level" : "2" }, { "id" : "r1_3", "hotel_id" : "1", "name" : "Doppia Uso singol", "level" : "1" }, { "id" : "r2", "hotel_id" : "2", "name" : "Singola", "level

setting fuelux datagrid source from backbone collection

左心房为你撑大大i 提交于 2019-12-02 08:14:01
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 data source var dataSource = new StaticDataSource({ columns: [ { property: 'username', label: 'Name',

For Loop over Backbone Collection

*爱你&永不变心* 提交于 2019-12-01 16:03:09
Fairly new to backbone, so this is a really basic question. I have a Backbone collection passed into a function and I can prove that it has been passed and that the models in the collection have ids. Here's how I'm setting the ids - convertToMapObjects: (results) => objectList = new ObjectList() results.each(result)-> testObj = new TestObject() testObj.set id = result.get("id") objectList.add(testObj) And in another function ( accessed through making the model trigger an event) - getIds: (objects) => ids = (object.id for object in objects) I think the issue may be because of how I'm iterating

BackboneJS model.url using collection.url

江枫思渺然 提交于 2019-12-01 15:51:52
From my understanding the default behavior of Backbone JS Models are to return the Collection's URL, unless the model has a urlRoot specified. I can't seem to get the behavior to work. From the documentation: model.url() ... Generates URLs of the form: "[collection.url]/[id]" by default, but you may override by specifying an explicit urlRoot if the model's collection shouldn't be taken into account. Here is my collection, and model respectively: var MyCollection = Backbone.Collection.extend({ model: Model, initialize: function(options){ this.options = options || {}; }, url: function(){ return

For Loop over Backbone Collection

流过昼夜 提交于 2019-12-01 14:09:07
问题 Fairly new to backbone, so this is a really basic question. I have a Backbone collection passed into a function and I can prove that it has been passed and that the models in the collection have ids. Here's how I'm setting the ids - convertToMapObjects: (results) => objectList = new ObjectList() results.each(result)-> testObj = new TestObject() testObj.set id = result.get("id") objectList.add(testObj) And in another function ( accessed through making the model trigger an event) - getIds: