Backbone.js 如何通过下划线.js读取模型和集合值

Backbone.js 如何通过下划线.js读取模型和集合值,backbone.js,underscore.js,Backbone.js,Underscore.js,我的观点是绑定模型和集合 var editUserPanel = new List.EditUserPanel({ collection: roll_st, model: dm }); 我用过html <% _.each(items, function(item){ if(item.category == "STGroup") { %> <optio

我的观点是绑定模型和集合

 var editUserPanel = new List.EditUserPanel({
                    collection: roll_st,
                    model: dm
                });
我用过html

  <%  _.each(items, function(item){ if(item.category == "STGroup") { %>
    <option selected> <%= item.name %> </option>
   <% } }) %>


当我的视图仅绑定到集合时,我可以读取集合值。但当两者都绑定时,我会得到错误

在视图中编写序列化函数,该函数将读取模型或集合,并返回模板的预期键值对映射。在呈现模板时,使用serialize的输出作为dataObject

var View = Backbone.View.extend({
    serialize: function(){
        return {
            items:this.collection.toJSON(), //array from collection
            modelValues:this.model.toJSON() // map from model
        }
    },
    render: function(){
        this.$el.html(_.template(your_template_html, this.serialize()))
    }
})