【发布时间】:2013-09-06 22:05:15
【问题描述】:
我觉得自己很愚蠢,但我想不通。我正在尝试 Handlebars.js,但我无法让它显示来自 Twitter API 的数据。这是我得到的:
$.ajax({
url : 'http://twitter.com/statuses/user_timeline/alexlande.json',
dataType : 'jsonp',
success : function( tweets ) {
var source = $('#tweet-template').html();
var template = Handlebars.compile(source);
var context = tweets;
$('#container').html(template(context));
}
});
这不会在我的模板中显示任何内容,但以下代码按预期工作:
var source = $('#tweet-template').html();
var template = Handlebars.compile(source);
var context = { tweets : [
{ text : "This is a test tweet" },
{ text : "And this is yet another" },
{ text : "And you always need three test tweets, right?" }
]};
$('#container').html(template(context));
这很简单,我不明白,对吧?
【问题讨论】:
标签: handlebars.js