在我看来,我没有声明this.el,因为我以恐怖的方式创建它,但是这样事件就不会发生.
这是代码:
查看1:
App.Views_1 = Backbone.View.extend({
el: '#content',
initialize: function() {
_.bindAll(this, 'render', 'renderSingle');
},
render: function() {
this.model.each(this.renderSingle);
},
renderSingle: function(model) {
this.tmpView = new App.Views_2({model: model});
$(this.el).append( this.tmpView.render().el );
}
});
Run Code Online (Sandbox Code Playgroud)
观点2:
App.Views_2 = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render');
},
render: function() {
this.el = $('#template').tmpl(this.model.attributes); // jQuery template
return this;
},
events: {
'click .button' : 'test'
},
test: function() {
alert('Fire');
}
});
});
Run Code Online (Sandbox Code Playgroud)
当我点击".button"时没有任何反应.谢谢;
我有一个网络应用程序,我需要将数据打印成pdf.在后端我使用php,而在前端是一个javascript MVC框架(backbone.js).
我不知道是否仅使用javascript生成pdf(..然后使用数据缓存)或使用将调用将生成pdf的php页面的ajax ...什么是更好的解决方案?
当然,我需要能够打印,保存和使用pdf样式表.
谢谢.
如何防止Safari iOS中的过度滚动?我会使用触摸手势在网站上导航,但我不能.
我试过这个:
$(window).on('touchstart', function(event) {
event.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
但是通过这种方式我禁用了所有手势,事实上我无法通过捏合和捏合来缩放.
有解决方案吗 谢谢.
使用Requirejs,如果条件为真,我怎样才能加载模块?例如,如果用户是Admin,则加载文件a.js.
PS:我正在使用Backbone和Requirejs.
在我的骨干应用程序中,我加载3个集合,并在渲染功能中绑定"重置"事件.因此,通过这种方式,当我获取集合时,我会打印各种结果,但不能同时打印.
我会使用jquery延迟方法($ .when,$ .then)同时打印所有内容,如果我在视图上使用"绑定事件",如何执行此操作?
这是代码:
路由器:
App.Routers.test1 = Backbone.Router.extend({
routes: {
"/test" : "test"
},
initialize: function() {
// Models
this.Models_1 = new App.Collections.coll_1;
this.Models_2 = new App.Collections.coll_2;
this.Models_3 = new App.Collections.coll_3;
// Views
this.View_1 = new App.Views.view_1( {model: this.Models_1} );
this.View_2 = new App.Views.view_2( {model: this.Models_2} );
this.View_3 = new App.Views.view_3( {model: this.Models_3} );
},
test: function() {
$.when(
this.Models_1.fetch(),
this.Models_2.fetch(),
this.Models_3.fetch()
).then(function() {
// ?????????????????????????
// What should I do here?
// ?????????????????????????
});
}
});
Run Code Online (Sandbox Code Playgroud)
查看1:
App.Views.view_1 …Run Code Online (Sandbox Code Playgroud)