0
我試圖枚舉並構建以下撥弄Mustache.js:這裏未能枚舉部分中的對象與JSONP和小鬍子的JavaScript模板
$(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);
});
});
示例 - >http://jsfiddle.net/mhMJA/3/
它正確地記錄對控制檯的JSON響應,但似乎沒有建立模板。如果我只是將單個用戶傳遞給JSONP回調,它可以正常工作。
在此先感謝。
將您的代碼添加到問題 - jsfiddle是一個很棒的網站,但有時非常慢 - 它通常更好地包含您的代碼和jsfiddle示例..... – ManseUK 2012-01-13 12:00:24