1

ハンドルバーを使用して total_count 値と name,group of messages 配列の値を使用するにはどうすればよいですか? メッセージが配列として配置されているため、本当に問題に直面しています。

"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