【发布时间】:2012-03-24 15:47:08
【问题描述】:
好的,我有这个密钥对值数组,我将其用作我的模型:
var acs = [{'label':'input box'},{'label':'text area'}];
其余代码如下
var Action = Backbone.Model.extend({});
var action = new Action(acs);
var ActionView = Backbone.View.extend({
tagName:"li",
template: _.template($('#actions-template').html()),
events:{
"click":"makeInput"
},
render:function(){
$(this.el).html(this.template(this.model.toJSON()));
$(".hero-unit>ul").append(this.el);
return this;
},
makeInput:function(){
alert("im in");
}
});
var actionView = new ActionView({model:action});
actionView.render();
问题是关于视图。如果这是我想要的视图,我如何循环遍历我正在传递的模型
<script type="text/template" id="actions-template">
<% _.each(action, function(acs) { %>
<a class="btn"><%= label %></a>
<% }); %>
</script>
我的观点和我相信的循环有问题。有什么线索吗? 谢谢!
【问题讨论】:
-
stackoverflow.com/questions/4778881/… 也有不少解决方案。
标签: javascript backbone.js underscore.js underscore.js-templating