Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用手柄和主干解析模板时的问题_Javascript_Jquery_Backbone.js_Handlebars.js - Fatal编程技术网

Javascript 使用手柄和主干解析模板时的问题

Javascript 使用手柄和主干解析模板时的问题,javascript,jquery,backbone.js,handlebars.js,Javascript,Jquery,Backbone.js,Handlebars.js,如何使用total_count value和name的值,使用手柄的消息组数组?我真的面临着麻烦,因为消息已被放入数组 "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

如何使用total_count value和name的值,使用手柄的消息组数组?我真的面临着麻烦,因为消息已被放入数组

"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"
        }
    ]
}
]
“将每个型号作为li添加到ul”
_.each(此.model.models、函数(消息){
$(this.el).append(新项目视图({model:message}).render().el);
},这个);
“单个项目视图”
var itemView=Backbone.View.extend({//表示每条消息
标记名:“li”,
模板:handlebar.compile($('#消息列表项').html(),
初始化:函数(){
_.bindAll(这是“呈现”、“移除”);
this.model.bind('change',this.render);
},
渲染:函数(){
$(this.el).html(this.template(this.model.toJSON());
归还这个;
}
});
((目前不工作))
((目前不工作))
JSON
[
{
“总信息量”:“10”,
“信息”:[
{
“id”:“10”,
“名称”:“msg1”,
“集团”:{
“名称”:“数据12”,
“img_url”:“占位符_bn.png”
}
},
{
“id”:“11”,
“名称”:“msg2”
}
]
}
]