Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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
无法使用JSONP和Mustache JavaScript模板枚举对象中的多个节_Javascript_Jquery_Json_Jsonp_Mustache - Fatal编程技术网

无法使用JSONP和Mustache JavaScript模板枚举对象中的多个节

无法使用JSONP和Mustache JavaScript模板枚举对象中的多个节,javascript,jquery,json,jsonp,mustache,Javascript,Jquery,Json,Jsonp,Mustache,我试图列举并构建以下fiddle with mustach.js: $(function () { var choices = { "users": [ { "first_name": "Ryan", "last_name": "Pays", "pic_square": "/Global/profile/thumb/placeholder.jpg", "product_name": "Merli

我试图列举并构建以下fiddle with mustach.js:

$(function () {
    var choices = { "users": [
        {    "first_name": "Ryan",
            "last_name": "Pays",
            "pic_square": "/Global/profile/thumb/placeholder.jpg",
            "product_name": "Merlin - the complete box set",
            "product_picture": "/Global/products/full/box-set.jpg"
        },
        {    "first_name": "Eric",
            "last_name": "Li Koo",
            "pic_square": "/Global/profile/thumb/placeholder.jpg",
            "product_name": "Merlin - Series 4 volume 1",
            "product_picture": "/Global/products/full/box-set.jpg"
        },
        {    "first_name": "Abdul",
            "last_name": "Raouf",
            "pic_square": "/Global/profile/thumb/placeholder.jpg",    
            "product_name": "Merlin - the complete box set",
            "product_picture": "/Global/products/full/box-set.jpg"
        }]
    };
    $.getJSON("http://jsfiddle.net/echo/jsonp/?callback=?", choices, function (data) {
        console.log(data);
        var template = "<ul>{{#users}}" +
                        "<li>" +
            "<p><strong>{{first_name}} {{last_name}}</strong> likes {{product_name}}</p>" +
                        "</li>" +
                        "{{/users}}</ul>",
            html = Mustache.to_html(template, data);
        $('.wrapper').html(html);
    });
});
$(函数(){
变量选项={“用户”:[
{“名字”:“Ryan”,
“姓氏”:“支付”,
“pic_square”:“/Global/profile/thumb/placeholder.jpg”,
“产品名称”:“梅林-整套包装盒”,
“产品图片”:“/Global/products/full/box set.jpg”
},
{“名字”:“埃里克”,
“姓氏”:“李辜”,
“pic_square”:“/Global/profile/thumb/placeholder.jpg”,
“产品名称”:“梅林-系列4第1卷”,
“产品图片”:“/Global/products/full/box set.jpg”
},
{“名字”:“阿卜杜勒”,
“姓氏”:“Raouf”,
“pic_square”:“/Global/profile/thumb/placeholder.jpg”,
“产品名称”:“梅林-整套包装盒”,
“产品图片”:“/Global/products/full/box set.jpg”
}]
};
$.getJSON(“http://jsfiddle.net/echo/jsonp/?callback=?,选项,函数(数据){
控制台日志(数据);
var template=“
    {{{#users}}”+ “
  • ”+ “{{first_name}{{last_name}}喜欢{{product_name}}

    ”+ “
  • ”+ “{{/users}}
”, html=Mustache.to_html(模板、数据); $('.wrapper').html(html); }); });
此处示例->

它正确地将JSON响应记录到控制台,但似乎无法构建模板。如果我只向JSONP回调传递一个用户,那么它就可以正常工作


提前谢谢。

这不是你的错。JSFIDLE可以帮助您将JSON对象转换为以下格式

{"users[0][first_name]":"Ryan","users[1][first_name]":"Eric","users[2][first_name]":"Abdul","users[2][product_picture]":"/Global/products/full/box-set.jpg","users[1][product_picture]":"/Global/products/full/box-set.jpg","users[1][pic_square]":"/Global/profile/thumb/placeholder.jpg","users[1][product_name]":"Merlin - Series 4 volume 1","users[0][last_name]":"Pays","users[0][product_picture]":"/Global/products/full/box-set.jpg","users[1][last_name]":"Li Koo","users[0][product_name]":"Merlin - the complete box set","users[0][pic_square]":"/Global/profile/thumb/placeholder.jpg","users[2][last_name]":"Raouf","users[2][pic_square]":"/Global/profile/thumb/placeholder.jpg","users[2][product_name]":"Merlin - the complete box set","_":"1326530878282"}

我建议您编写自己的JSONP应用程序来避免这个问题。是我用来获取JSON对象的。

将您的代码添加到问题中-JSFIDLE是一个很棒的站点,但有时速度非常慢-最好包括您的代码和JSFIDLE示例。。。。。