我正在開發一個使用require js和Backbone的android應用程序。我必須將通過touchend事件從集合中獲取的模型傳遞給路由器。我該怎麼做?骨幹傳遞模型到路由器
define(["jquery", "underscore","backbone","handlebars", "views/CinemaView", "models/CineDati", "text!templates/listacinema.html"],
function($,_,Backbone,Handlebars,CinemaView, CineDati, template){
var ListaCinemaView = Backbone.View.extend({
template: Handlebars.compile(template),
events: {
"touchend" : "Details"
},
initialize : function(){
var self = this;
$.ajax({
url: 'http://www.cineworld.com/api/quickbook/cinemas',
type: 'GET',
data: {key: 'BwKR7b2D'},
dataType: 'jsonp', // Setting this data type will add the callback parameter for you
success: function (response, status) {
// Check for errors from the server
if (response.errors) {
$.each(response.errors, function() {
alert('An error occurred. Please Try Again');
});
} else {
$.each(response.cinemas, function() {
var cinema = new CineDati();
cinema.set({ id : this.id, name : this.name , cinema_url : this.cinema_url, address: this.address, postcode : this.postcode , telephone : this.telephone });
self.model.add([cinema]);
});
self.render();
}}
});
},
events : {
"#touchend" : Dettagli
},
render : function(){
$(this.el).empty();
$(this.el).html(template).append(
_.each(this.model.models, function (cinema) {
$("#lista").append(new CinemaView({
model: cinema
}).render().el); }, this));
return this;
},
Dettagli : function(){
Backbone.history.navigate(this.model , {trigger: "true"});
}
});
return ListaCinemaView;
});
非常感謝Will,你一直非常樂於助人!我已經檢查過marionette.js,我想我會用它來做我未來的應用程序! :) –
很高興我幫助,奧古斯托。祝你的項目好運。 –
當某人在http:// website/model_id上刷新頁面時,此解決方案不會對此進行解釋。你失去了對模型的引用。 –