0

我不知道我做错了什么,但所有项目都应该在标签<li>项目内,</li>但只有第一项是,可以是什么?

javascript:

$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?", function (data) {

    var titles = data.query.results.channel.item.map(function(item) {
    return item.title;

    });

    $(".container-list-podcast ul").append('<li>' + titles.join('</li>'));

});

jsfiddle

4

6 回答 6

4

这条线需要:

 $(".container-list-podcast ul").append('<li>' + titles.join('<li>'));

编辑以匹配下面 TJ Crowder 的建议。

于 2013-08-08T17:36:15.193 回答
3

您没有后续的开始<li>标签。你可能的意思是:

$(".container-list-podcast ul").append('<li>' + titles.join('</li><li>') + '</li>');
// This opens the first item (only) ----^                    ^    ^         ^
// This closes each item except the last --------------------+    |         |
// This opens the second one onward ------------------------------+         |
// This closes the last one ------------------------------------------------+

或者,如果您想依靠结束</li>标签是可选的这一事实,它可能是:

$(".container-list-podcast ul").append('<li>' + titles.join('<li>'));
于 2013-08-08T17:36:26.287 回答
0

更新代码http://jsfiddle.net/m627u/

$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?", function (data) {

    var titles = data.query.results.channel.item.map(function(item) {
    return '<li>'+item.title+'</li>';

    });
    $(".container-list-podcast ul").append(titles);
});

您将集体字符串放入<li>,而不是每个标题。

于 2013-08-08T17:39:39.843 回答
0
$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?", function (data) {

    var titles = data.query.results.channel.item.map(function(item) {
    return item.title;

    });

    $.each(titles, function(key, value){
        $(".container-list-podcast ul").append('<li>' + value + '</li>');
    });                

});
于 2013-08-08T17:39:54.077 回答
0

这是工作演示

$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?", function (data) {

    var titles = data.query.results.channel.item.map(function(item) {
    return item.title;

    });

    $(".container-list-podcast ul").append('<li>' + titles.join('</li><li>'));

});
于 2013-08-08T17:40:14.780 回答
0

这是解决方案的修改代码http://jsfiddle.net/Cf5QU/2/

 $.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?", function (data) {

    var titles = data.query.results.channel.item.map(function(item) {
    return item.title;

    });

    $(".container-list-podcast ul").html('<li>' + titles.join('</li>' + '<br>' + '<li>'));

});

你必须添加断线和新的李

于 2013-08-08T17:48:27.673 回答