【发布时间】:2011-07-27 20:59:13
【问题描述】:
我听说了关于 Mustache 的精彩内容,并决定试一试。
我想弄清楚如何在 jQuery 中使用 Mustache 模板。我已经找了几天了。
小胡子可以在这里找到:https://github.com/janl/mustache.js/
这是我的尝试:
$.getJSON('get_fullname.asp', {name: 'johnny'}, function(data, status, xhr) {
var template = '<h1>{{NAME}}</h1><p>test</p>';
strHTML = Mustache.to_html(template, data);
$('#container').html( strHTML );
});
我的 JSON 数据返回 [{"NAME":"John","MIDDLE":"A","LAST":"Smith"}]
我得到的只是<p>test</p>。
我也尝试过使用这个模板,但仍然得到<p>test</p>。
var template = '{{#NAME}}<h1>.</h1>{{/NAME}}<p>test</p>';
我错过了什么?
【问题讨论】:
标签: javascript jquery templates mustache