私はアンドロイドのアプリケーションをrequire jsとBackboneを使って開発しています。コレクションから取ったモデルを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;
});
ありがとうございますウィル、あなたはとても助けになりました!私はすでにmarionette.jsをチェックしており、私はそれを私の将来のアプリケーションに使うつもりだと思う! :) –
嬉しい私は、アウグストを助けた。あなたのプロジェクトに幸運。 –
この解決策は、誰かがhttp:// website/model_idにいったんページを更新した時点を考慮していません。あなたはモデルへの参照を失います。 –