append()listview Javascript后丢失JQuery Mobile CSS样式

Lost of JQuery Mobile CSS Style after append() listview Javascript

本文关键字:JQuery Mobile CSS 样式 listview Javascript append      更新时间:2023-09-26

我知道以前有人问过这个问题,但我已经尝试了所有能找到的解决方案,但都无济于事。

我的jqm样式没有初始化,很像这个家伙的问题:JQuery-mobile->append()是否删除CSS?我尝试过.trick("create")和listview("fresh")方法,甚至两者的组合。

翡翠:

    #category(data-role='page')
      a(href='#automobile', data-transition='slide', onclick="return loadItemsBrief('automobile');")
          | Automobile
    ... //code reduced here
    #automobile(data-role='page')
     div(data-role='content')
       div#refresh(data-role='fieldcontain')
         ul#autoList(data-role='listview', data-divider-theme='b', data-inset='true')

Javascript(separate.js)

    function loadItemsBrief(cat){ 
     $.getJSON(''+cat, function (json) {
      $.each(json.items,function(i,data) {
       $('#autoList').append('<li data-theme="c"><a href="" data-transition="slide" class="touchableButton"><div style="display: inline-block"><img style="width: 100px; height: 125px" src=""'+data.fileUrls[0]+'></div><div style="display: inline-block"><h3>Title: '+data.name+'</h3><h3>Price: '+data.minBid+'</h3><h3>Condition: '+data.condition+'</h3></div></a></li>'); //tried .trigger('create') here
      });
      $('#autoList').listview('refresh'); //also tried placing .listview('refresh') in inner most layer
     });
    }

firebug给我的错误是:

TypeError: $(...).listview is not a function
$("#autoList").listview("refresh");

我们将非常感谢您的帮助,谢谢!

显然,在尝试了所有可能的解决方案后,我尝试将JQuery版本更改为1.8.3,并将JQM版本保留为1.3.1。现在所有列表视图都正常刷新。