Jquery Mobile动态生成列表

时间:2012-12-21 09:19:59

标签: javascript jquery jquery-mobile

我正在使用JQuery Mobile在可折叠页面中动态生成列表。

但如果我在带有项目列表的可折叠页面之前设置页面,那么CSS就会搞砸了。

生成列表项的代码:

var li = domCreationService.createListItem({"data-corners":"false", "data-shadow":"false", 
    "data-iconshadow":"true", "data-wrapperels":"div", "data-icon":"arrow-r", "data-iconpos":"right", 
    "data-theme":"c", "class":"ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-thumb ui-li-last ui-btn-up-c"});

  var outherDiv = domCreationService.createDiv({"class": "ui-btn-inner ui-li"});
  li.appendChild(outherDiv);
  var innerDiv = domCreationService.createDiv({"class": "ui-btn-text"});
  outherDiv.appendChild(innerDiv);
  var link = domCreationService.createLinkItem({href: "#dialog.html",id: "dialog", "class": "ui-link-inherit", "data-rel": "dialog"});
  innerDiv.appendChild(link);
  link.appendChild(domCreationService.createImg({src: ("images/" + key + ".jpg"), "class": "ui-li-thumb"}));
  var obj = domCreationService.createHTag(3, {"class": "ui-li-heading"});
  obj.innerHTML = name;
  link.appendChild(obj);
  obj = domCreationService.createPTag({"class": "ui-li-desc"});
  obj.innerHTML = beskrivning;
  outherDiv.appendChild(domCreationService.createSpan({"class": "ui-icon ui-icon-arrow-r ui-icon-shadow"}));
  link.appendChild(obj);

这是它第一页时的样子:

<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="c" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-thumb ui-li-last ui-btn-hover-c">
<div class="ui-btn-inner ui-li">
    <div class="ui-btn-text">
        <a href="#dialog.html" id="dialog" class="ui-link-inherit" data-rel="dialog">
            <img src="images/picture.jpg" class="ui-li-thumb">
            <h3 class="ui-li-heading">Test</h3>
            <p class="ui-li-desc">Lorem Ipsum</p>
        </a>
    </div>
    <span class="ui-icon ui-icon-arrow-r ui-icon-shadow">&nbsp;</span>
</div>
</li>

但是当它不是第一页时,我得到了这个:

<li data-corners="false" data-shadow="false" data-iconshadow="true" data-wrapperels="div" data-icon="arrow-r" data-iconpos="right" data-theme="c" class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-thumb ui-li-static ui-btn-up-c">
<div class="ui-btn-inner ui-li ui-corner-top ui-corner-bottom ui-li-static ui-btn-up-c">
    <div class="ui-btn-text">
        <a href="#dialog.html" id="dialog" class="ui-link-inherit" data-rel="dialog">
            <img src="images/picture.jpg" class="ui-li-thumb">
            <h3 class="ui-li-heading">Test</h3>
            <p class="ui-li-desc">Lorem Ipsum</p>
        </a>
    </div>
    <span class="ui-icon ui-icon-arrow-r ui-icon-shadow">&nbsp;</span>
</div>
</li>

注意附加的第二个div类的更改。

以前有人经历过这样的事情吗?

1 个答案:

答案 0 :(得分:1)

在jQM listview中动态添加内容时,您需要执行:

$('#listID').listview('refresh');

在列表生成结束时。此方法将重新放置所有新的列表元素。