사이트가 백본으로 개발되었습니다. 나는 애플 리케이션을 만들고 내부에 하위 뷰를 생성한다.백본 하위 뷰 이벤트
이 하위 뷰에서는 div (id는 close
)를 사용할 수 있으며 이벤트를 트리거해야합니다. 하지만 이벤트가 시작되지 않는 이유는 모르겠습니다. 이 사건에 내가 왜 잘못 됐는지 설명해 주시겠습니까?
문제는 Search.Views.Product
이며, 이벤트가있는 하위 뷰입니다.
이
(나는 잘 응용 프로그램을 읽고 뭔가를 잘라) 내 응용 프로그램입니다 ://main app
Search.Views.App = Backbone.View.extend({
initialize:function() {
var this_app = this;
this.subView = {
Product : new Search.Views.Product({
base_url:this_app.base_url || '',
collection : new Search.Collections.Products()
})
}
},
render:function (options) {
var defaults = {
products:{
wrap:"ul",
id:"product-results",
class:""
}
}
var settings = $.extend(true, defaults, options);
this.renderProducts(settings);
},
renderProducts:function (settings) {
$(this.id).html(this.wrap(this.subView.Product.getTemplate(settings.products.view), settings.products));
}
});
//collection
Search.Collections.Products = Backbone.Collection.extend({
model: Search.Models.Product,
initialize:function() {
}
});
Search.Models.Product = Backbone.Model.extend({
defaults: search.product.defaults || {},
initialize:function() {
}
});
Search.Views.Product = Backbone.View.extend({
//doesn't fire this event!!!--------------------------------------
events: {
'click #close': 'closeResults',
'click': 'closeResults'
},
closeResults:function (event) {
console.log('Close results');
$('#close').html('test');
},
getTemplate:function (view) {
var data = this.collection.toJSON() || this.model.toJSON();
data = this.normalize(data);
var template = Handlebars.compile($(this.template).html());
return template({view:view, results:data});
},
render:function() {
// non utilizzato per ora
return this;
}
});
작동하지 않습니다. 이전에 수업에서 시도했습니다. –
좋습니다. 더 일반적인 '클릭'바인딩 화재가 있습니까? –
아니요 발사하지 않습니다. –