C:\Users\Administrator\Desktop\gulp\app.js
jQuery(document).ready(function($) {
var FirstModel = Backbone.Model.extend({
defaults: {
name: 'Lionel',
team: "Viet Nam",
no: 10
}
});
var model1 = new FirstModel({
name: 'Lionel 1',
team: "VietNam",
no: 16
});
var model2 = new FirstModel({
name: 'Lionel 2',
team: "India",
no: 17
});
var model3 = new FirstModel({
name: 'Lionel 3',
team: "Korea",
no: 18
});
var MyCollection = Backbone.Collection.extend({
model: FirstModel
});
var MycollectionObj = new MyCollection([model1, model2, model3]);
var ModelView = Backbone.View.extend({
collection: MycollectionObj,
initialize: function() {
this.render();
},
render: function() {
_.each(this.collection.toJSON(), function(model) {
console.log(model.name + " , " + model.team);
});
}
});
vmodel = new ModelView();
});
C:\Users\Administrator\Desktop\gulp\app.js
jQuery(document).ready(function($) {
var FirstModel = Backbone.Model.extend({
defaults: {
name: 'Lionel',
team: "Viet Nam",
no: 10
}
});
var model1 = new FirstModel({
name: 'Lionel 1',
team: "VietNam",
no: 16
});
var model2 = new FirstModel({
name: 'Lionel 2',
team: "India",
no: 18
});
var model3 = new FirstModel({
name: 'Lionel 3',
team: "Korea",
no: 18
});
var MyCollection = Backbone.Collection.extend({
model: FirstModel
});
var MycollectionObj = new MyCollection([model1, model2, model3]);
var ModelView = Backbone.View.extend({
collection: MycollectionObj,
initialize: function() {
this.render();
},
render: function() {
var data = _.where(this.collection.toJSON(), {no: 18});
console.log(data);
}
});
vmodel = new ModelView();
});
C:\Users\Administrator\Desktop\gulp\app.js
jQuery(document).ready(function($) {
var FirstModel = Backbone.Model.extend({
defaults: {
name: 'Lionel',
team: "Viet Nam",
no: 10
}
});
var model1 = new FirstModel({
name: 'Lionel 1',
team: "VietNam",
no: 16
});
var model2 = new FirstModel({
name: 'Lionel 2',
team: "India",
no: 18
});
var model3 = new FirstModel({
name: 'Lionel 3',
team: "Korea",
no: 18
});
var MyCollection = Backbone.Collection.extend({
model: FirstModel
});
var MycollectionObj = new MyCollection([model1, model2, model3]);
var ModelView = Backbone.View.extend({
collection: MycollectionObj,
initialize: function() {
this.render();
},
render: function() {
var data = _.findWhere(this.collection.toJSON(), {no: 18}); // retrun result first
console.log(data);
}
});
vmodel = new ModelView();
});
C:\Users\Administrator\Desktop\gulp\app.js
jQuery(document).ready(function($) {
var FirstModel = Backbone.Model.extend({
defaults: {
name: 'Lionel',
team: "Viet Nam",
no: 10
}
});
var model1 = new FirstModel({
name: 'Lionel 1',
team: "VietNam",
no: 16
});
var model2 = new FirstModel({
name: 'Lionel 2',
team: "India",
no: 18
});
var model3 = new FirstModel({
name: 'Lionel 3',
team: "Korea",
no: 18
});
var MyCollection = Backbone.Collection.extend({
model: FirstModel
});
var MycollectionObj = new MyCollection([model1, model2, model3]);
var ModelView = Backbone.View.extend({
collection: MycollectionObj,
initialize: function() {
this.render();
},
render: function() {
var data = _.pluck(this.collection.toJSON(), "name");
console.log(data); // return result first
}
});
vmodel = new ModelView();
});