1

我正在使用 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 类中的更改。

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

4

1 回答 1

1

您需要执行的动态添加内容到 jQM 列表视图的位置:

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

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

于 2012-12-21T09:23:01.213 回答