我想知道您对javascript模板引擎的看法,您认为哪一个在性能方面更好?
我找到了一些人们进行基准测试的链接:
http://jsperf.com/jquery-template-table-performance/15
http://jsperf.com/jquery-template-table-performance/8
http://www.viget.com/extend/benchmarking-javascript-templating-libraries/
我正在尝试将2个模型传递给视图,但它似乎无法正常工作.这是我的例子:http://jsfiddle.net/kahhor/jp4B6/14/你可以看到第二个警告显示未定义...
可能是我有错误的做法.我要做的是:在View1绑定事件'change'中Model1...通过单击按钮View2,调用函数,Model1其中更改值,并自动呈现View1,因为它被绑定以更改事件.
但是不要忘记它View2也有它自己Model2,我在视图之外创建并且传递它new View2({model:Model2});.
起初看起来可能很混乱,但我认为骨干可以做到这一点很简单.我只是不知道该怎么做:)
谢谢,
我打算使用backbone.js和underscore.js来创建网站,我将有很多下划线模板:
<script type="text/template" id="search_template">
<p id="header">
//header content will go here
</p>
<p id="form">
<label>Search</label>
<input type="text" id="search_input" />
<input type="button" id="search_button" value="Search" />
</p>
<p id="dynamic_date">
//dynamic data will be displayed here
</p>
</script>
Run Code Online (Sandbox Code Playgroud)
当然,我的模板会复杂得多.
由于我将拥有大量的内容,因此我不希望每次加载页面时都加载所有模板.我想找到一个解决方案,我只能在使用它时加载特定模板.
另一件事是,我的大多数模板将具有相同的结构,只<p id="form"></p>和<p id="dynamic_date"></p>内容会有所不同.
你能告诉我怎么办?
谢谢,
我有这种观点结构:
window.templateLoaderView = Backbone.View.extend({});
window.PopupView = templateLoaderView.extend({
initialize: function () {
this.PopupModel = new PopupModel();
this.event_aggregator.bind("tasks_popup:show", this.loadTaskPopup);
},
render: function() {
template= _.template($('#'+this.PopupModel.templateName).html());
$(this.el).html(template(this.PopupModel.toJSON()));
$('#'+this.PopupModel.containerID).html(this.el);
},
loadTaskPopup: function() {
this.PopupModel.loadTemplate("popupTask_templateHolder", "/js/templates/popup_task.html", "1", "container_dialog");
this.render();
}
});
window.TaskbarView = templateLoaderView.extend({
initialize: function () {
this.TaskbarModel = new TaskbarModel();
this.PopupModel = new PopupModel();
},
loadTaskbarPopup: function() {
this.event_aggregator.trigger("tasks_popup:show");
}
});
Run Code Online (Sandbox Code Playgroud)
所以我想在另一个视图中运行runf函数.据我所知,我需要以某种方式绑定它们.是否可以在初始化函数中绑定它们?
我在这里看到的例子:Backbone.js - 从一个视图绑定到另一个视图?.他们创建两个对象,而不是以某种方式绑定它们.
提前致谢,