1

我如何使用总计数值和名称的值,使用车把的消息数组组?我真的遇到了麻烦,因为 messages 已被放置为 array 。

"Adds each model as li to ul"

 _.each(this.model.models, function (message) {
            $(this.el).append(new itemView({model:message}).render().el);
 }, this); 


"Single item view"

var itemView = Backbone.View.extend({          //Represents each message

    tagName:"li",


    template:Handlebars.compile($('#message-list-item').html()),

    initialize: function () {
        _.bindAll(this, 'render', 'remove');
        this.model.bind('change', this.render);
    },

    render:function () {
        $(this.el).html(this.template(this.model.toJSON()));
        return this;
    }

});

<!-- Item View Template -->
 <script type="text/template" id="message-list-item">
    <div><a title="{{group.name}}"></a></div>    ((currently not working))
    <div><a title="{{total_messages}}"></a></div> ((currently not working))
    <div>
 </script>
<!--  Item View Template -->



JSON
 [
   {
    "total_messages": "10",
    "messages": [
        {
            "id": "10",
            "name": "msg1",
            "group": {
                "name": "Data12",
                "img_url": "placeholder_bn.png"
            }
        },
        {
            "id": "11",
            "name": "msg2"
        }
    ]
}
]
4

0 回答 0