好的,所以我有这个密钥对值数组,我将其用作我的模型:
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>
我的观点和我相信的循环有问题。有什么线索吗?谢谢!