我試圖用這個 嘗試過濾一個特定的數據。backbonejs過濾數據時傳遞參數
在菜單中,我有一個lista,我希望當我點擊一個我只能得到關於它的信息。
HourView= Backbone.View.extend({
initialize: function(){
this.template = _.template($("#HourView").html());
},
render: function() {
var col = new HourCollection();
$.ajax({ //zeptojs
async: true
});
col.fetch({ success: function() {
}});
//col.fetch({reset: true});
$.ajax({ //zeptojs
async: false
});
col.where({"name": "Gamarra"});
this.$el.html(this.template({ horarios: col.toJSON() }));
return this;
}
});
[ { 「名稱」: 「加馬拉」, 「VES」:[ 「00:00」 ], 「GRAU」:[ 「01:00」 ] } , { 「名稱」: 「格勞」, 「VES」:[ 「08:00」 ], 「GRAU」:[ 「07:00」 ] } ]
我想這
initialize: function(){
this.collection = new HourCollection();
this.collection.fetch({reset: true});
this.collection.fetch({success: function(collection) {
collection = collection.where({"name": "Gamarra"});
console.log(JSON.stringify(collection))
}});
this.collection.on("sync", this.render, this);
this.template = _.template($("#HourView").html() );
},
render: function() {
this.$el.html(this.template({ hs: this.collection.toJSON() }));
return this;
}
{ \t \t \t col.where({「nombre」:「Gamarra」}); \t \t}});但它不工作......以及 – Osgux
該代碼中是否存在copy'n'paste錯誤? Zepto支持'async:true'嗎?你爲什麼不在'col'上使用事件來觸發渲染?通常情況下,你需要在'initialize','col.fetch({reset:true})'中實例化這個集合,然後監聽''reset''事件來觸發'render'(或多或少)。 –
是的,但我需要這部分「[{」nombre「:」Gamarra「,」VES「:[」00:00「],」GRAU「:[」01:00「]}]」 – Osgux