【问题标题】:jQuery templates pulling in JSON feed from TwitterjQuery 模板从 Twitter 中提取 JSON 提要
【发布时间】:2011-03-30 11:28:46
【问题描述】:

我正在尝试获取 Twitter 提要,使用 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>

和想法?

【问题讨论】:

    标签: jquery templates twitter


    【解决方案1】:
    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");
    });
    

    【讨论】:

    • 谢谢,效果很好!向我展示 jsfiddle 的额外积分。很有用。您认为这可以使用 API 完成吗?我试过: $.ajax({ url: 'search.twitter.com/search.json?q=from:ladygaga&callback=?', data: data, success: callback});但这是空白的。我无法弄清楚为什么,它似乎甚至没有尝试请求......
    猜你喜欢
    • 1970-01-01
    • 2012-06-24
    • 2015-11-18
    • 1970-01-01
    • 2016-11-06
    • 2012-01-31
    • 2014-10-07
    • 1970-01-01
    • 2013-06-14
    相关资源
    最近更新 更多