如何将此 RSS 提要放入 jQuery 列表视图中?

发布于 2024-12-23 02:31:22 字数 356 浏览 2 评论 0原文

好吧,我找到了这个 RSS 插件,我想在网页中显示它,但我希望它在 jQuery 列表视图中,所以每个项目都是一个列表项目,有人可以向我解释一下该怎么做吗?我把jsfiddle链接放在下面了!谢谢
http://jsfiddle.net/8qhZP/
这是我找到该插件的实际来源
http://www.jquery4u.com/plugins/jquery-rss-提要显示实时/

Okay I found this RSS plugin and I want to display it inside a webpage, but I want it to be in a jQuery listview, so each item is a list item, could someone please explain to me how to do it? I put the jsfiddle link below! Thanks
http://jsfiddle.net/8qhZP/
And this is the actual source where I found the plugin
http://www.jquery4u.com/plugins/jquery-rss-feed-display-live/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哥,最终变帅啦 2024-12-30 02:31:22

实现此目的的最简单方法是将 RSS 提要转换为 JSON 对象。这样您就可以使用 JSONP 调用 url,然后使用 jQuery 模板引擎解析输出。

1) 使用 Yahoo Pipes 将 RSS feed 转换为 JSON feed(也可以合并 RSS feed)

http://jquery4u.com/ rss/

变为

Yahoo JSON Pipe Output

2) 使用 jQuery 渲染 JSON feed模板引擎如 json2html

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://json2html.com/js/jquery.json2html-2.5-min.js"></script>

<script type="text/javascript">
var transform = {tag:'li',children:[
                    {tag:'a',src:'.link',html:'.title'},
                    {tag:'br'},
                    {tag:'span',html:'.description'}
                ]};

$.getJSON("http://pipes.yahoo.com/pipes/pipe.run?_callback=?", {"_id":"f5e0edec7594378e719cf18c53f8a26c","_render":"json"}, function(data){
    $('#rssFeed').json2html(data.value.items,transform);
});   
</script>

<ul id='rssFeed'></ul>

Easiest way to accomplish this is to get the RSS feed converted into a JSON object. This way you can call the url using JSONP and then parse the output using a jQuery template engine.

1) Convert the RSS feed into a JSON feed using Yahoo pipes (can also combine RSS feeds)

http://jquery4u.com/rss/

into

Yahoo JSON Pipe Output

2) Render the JSON feed using a jQuery templating engine like json2html

<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://json2html.com/js/jquery.json2html-2.5-min.js"></script>

<script type="text/javascript">
var transform = {tag:'li',children:[
                    {tag:'a',src:'.link',html:'.title'},
                    {tag:'br'},
                    {tag:'span',html:'.description'}
                ]};

$.getJSON("http://pipes.yahoo.com/pipes/pipe.run?_callback=?", {"_id":"f5e0edec7594378e719cf18c53f8a26c","_render":"json"}, function(data){
    $('#rssFeed').json2html(data.value.items,transform);
});   
</script>

<ul id='rssFeed'></ul>
堇年纸鸢 2024-12-30 02:31:22

如果您没有被迫使用 jquery feed rss live 插件 你指出,那么你可以使用 其他插件:解析 RSS jQuery。

stackoverflow 上的另一篇文章也对此进行了讨论:使用 jquery 解析 rss 并附有示例和一些文档。

因此,重用 Nathan Strutz 给出的示例
你可以这样做:

   jQuery.getFeed({
      url: 'your url',
      success: function(feed) {
         //append your list element and then refresh the list
         $('#myList').append('<li>'+feed.title+'</li>');
         $('#myList').listview('refresh');
      }
   });

希望它符合你的需求。

If you are not forced to use the jquery feed rss live plugin you point out, then you could use that other plugin: Parse RSS with jQuery.

It's also discussed on another post on stackoverflow: parse rss with jquery with examples and some documentation.

So, reusing the example given by Nathan Strutz
you could just do something like:

   jQuery.getFeed({
      url: 'your url',
      success: function(feed) {
         //append your list element and then refresh the list
         $('#myList').append('<li>'+feed.title+'</li>');
         $('#myList').listview('refresh');
      }
   });

Hope it fits your needs.

嘦怹 2024-12-30 02:31:22

RSS 插件似乎默认生成一个列表。 演示页面 生成段落,但这是因为它已明确配置为在源代码包含此行:

newsfeed.setentrycontainer("p");

从配置中取出此行应生成 html 列表。

我对 jQuery 列表视图了解不多(它适用于移动页面,对吧?),但我想如果您在加载 RSS 提要之后初始化 jQuery 列表视图,它应该可以工作。

祝你好运!

The RSS plugin seems to generate a list by default. The demo page generates paragraphs, but that's because it's explicitly configured to do that in the source with this line:

newsfeed.setentrycontainer("p");

Taking this line out of the config should generate the html list.

I don't know much about the jQuery listview (it's for mobile pages right?), but I guess that if you initialise the jQuery listview after the RSS feed is loaded, it should work.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文