gpt4 book ai didi

jQuery 模板从 Twitter 中提取 JSON 提要

转载 作者:行者123 更新时间:2023-12-01 08:23:55 25 4
gpt4 key购买 nike

我正在尝试获取 Twitter feed,可以使用 search API或者只是使用 A standard JSON call使用下面的代码我只得到一个空白页。我已经包含了所有正确的 jQuery 元素,并使用 Flikr API 对其进行了测试。 (并更改了相关模板部分)

  <script>
$().ready(function() {

$(document).ajaxComplete(function() {
$("body").attribute({message: ""});
});

$.getJSON('http://twitter.com/status/user_timeline/ladygaga.json?count=10&callback=?', function(data) {

$.template("imageTmpl", $("#imagesTmpl"));
$.tmpl("imageTmpl", data, {

}).appendTo("#img_list");
});
});
</script>
</head>
<body>
<article id="img_list">
<script id="imagesTmpl" type="text/x-jquery-tmpl">
{{each items}}
{{if $index <= 4}}
${$text}

{{/if}}
{{/each}}
</script>
</article>
</body>

和想法?

最佳答案

  1. 更改您的模板语法,在这种情况下您不需要每个语法,模板引擎默认显示它获取的每个数组键

  2. 请注意括号 - 正确的语法始终是 ${text}。

find working demo here ...

这是 html:

<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script>
</head>
<body>
<article id="img_list">
<ul>
<script id="imagesTmpl" type="text/x-jquery-tmpl">
<li>${text}<br/><br/></li>
</script>
</ul>
</article>
</body>

这是一个稍微修改过的 js:

$.getJSON('http://twitter.com/status/user_timeline/ladygaga.json?count=10&callback=?', function(data) {
$.template("imageTmpl", $("#imagesTmpl"));
$.tmpl("imageTmpl", data).appendTo("#img_list");
});

关于jQuery 模板从 Twitter 中提取 JSON 提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5485671/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com