【发布时间】:2011-07-01 22:08:02
【问题描述】:
这涉及 jQuery Mobile 1.0 Beta 1
我喜欢 jQuery Mobile,但看在上帝的份上,我不知道如何动态添加列表项。我第一次尝试不绑定 pagebeforecreate 事件——这些项目被附加到 DOM 但不可见,即使我尝试调用以下的许多组合:
$("#categories").listview();
$("#categories").listview('refresh');
$("#categories").listview('refresh', true);
我得到“表达式 'b[0]' [undefined] 的结果不是对象。”错误。
然后我想我可以绑定到 pagebeforecreate 事件以在 jQuery Mobile 发挥它的魔力之前附加 li-items。但是,这无济于事..与以前的结果相同。
$().ready(function() {
$("#browse-categories").live('pagebeforecreate', function() {
$.get('http://foo.com/api/categories.xml', function(data) {
$xml = $(data);
$xml.find('entry').each(function() {
$("#categories").append("<li>" + $(this).find('title').text() + "</li>")
});
});
});
});
HTML:
<div data-role="page" id="browse-categories">
<div data-role="header">
<h1>Categories</h1>
</div>
<div data-role="content">
<ul data-role="listview" id="categories">
</ul>
</div>
<div data-role="footer">
<h4>Page Footer</h4>
</div>
</div>
那是什么鬼?
【问题讨论】:
标签: jquery listview jquery-mobile