我正在使用Controller來獲取URL。我需要一種方法將參數放在這個POST中。這些參數由用戶在查看&尚未存儲選擇(我不知道如何存儲)backbone.js搜索過濾系統[結構]
目前我設法
- 顯示&路線觀與搜索結果來自API
- 顯示未來並刷新頁面,當有人選擇過濾選項
問題
- 我不知道如何來記錄用戶點擊了哪些
- 我如何「重郵報」這樣我就可以得到新的結果集 的
- 我讀,說人說,POST取應型號進行, 集合是用於存儲多個模型,我不知道在這個 的情況下?
類別 Jobs.js
define([
'jquery',
'underscore',
'backbone',
'models/filter'
], function($, _, Backbone,JobListFilterModel){
var Jobs = Backbone.Collection.extend({
url: function() {
return 'http://punchgag.com/api/jobs?page='+this.page+''
},
page: 1,
model: JobListFilterModel
});
return Jobs;
});
類別Filter.JS
define([
'jquery',
'underscore',
'backbone',
'models/filter'
], function($, _, Backbone,JobListFilterModel){
console.log("Loaded");
var Jobs = Backbone.Collection.extend({
url: function() {
return 'http://punchgag.com/api/jobs?page='+this.page+''
},
page: 1,
model: JobListFilterModel
});
// var donuts = new JobListFilterModel;
// console.log(donuts.get("E"));
return Jobs;
});
模型 Filter.js
define([
'underscore',
'backbone'
], function(_, Backbone){
var JobFilterModel = Backbone.Model.extend({
defaults: {
T: '1', //Task/Event-based
PT: '1', //Part-time
C: '1', //Contract
I: '1' //Internship
}
});
// Return the model for the module
return JobFilterModel;
});
模型 Job.js
define([
'underscore',
'backbone'
], function(_, Backbone){
var JobModel = Backbone.Model.extend({
defaults: {
name: "Harry Potter"
}
});
// Return the model for the module
return JobModel;
});
Router.js
define([
'jquery',
'underscore',
'backbone',
'views/jobs/list',
'views/jobs/filter'
], function($, _, Backbone, JobListView, JobListFilterView){
var AppRouter = Backbone.Router.extend({
routes: {
// Define some URL routes
'seeker/jobs': 'showJobs',
'*actions': 'defaultAction'
},
initialize: function(attr)
{
Backbone.history.start({pushState: true, root: "/"})
},
showJobs: function()
{
var view = new JobListView();
view.$el.appendTo('#bbJobList');
view.render();
console.log(view);
var jobListFilterView = new JobListFilterView();
jobListFilterView.render()
},
defaultAction: function(actions)
{
console.info('defaultAction Route');
console.log('No route:', actions);
}
});
var initialize = function(){
console.log('Router Initialized');// <- To e sure yout initialize method is called
var app_router = new AppRouter();
};
return {
initialize: initialize
};
});
一些例子將是真棒。謝謝
所以我正確地說如果過濾器按鈕被點擊,我打電話給refreshJobs。但在此之前,我需要更新模型中的參數? – TransformBinary
正確,您需要先更新JobFilterModel的實例屬性。例如: jobFilterModel = new JobFilterModel({}); jobFilterModel.set(「T」,2); //只是一個例子 jobFilterModel.refreshCollection(jobCollection); 您可以通過綁定模型更改來自動調用refreshCollection,使其更加「無縫」,但是更難控制何時從您的服務器實際拉動(即修改多個過濾器值時,您只需拉一次.. )。 – Enders