.listview() is not a function error when creating a dynamic listview in jquery mobile

寵の児 提交于 2019-12-17 14:57:59

问题


I am trying to create a dynamic listview in jquery mobile, after querying the facebook api, to retrieve a user's news feed. Here's part of my mark up:

markup += '<li><a href=""><img src="https://graph.facebook.com/' + id + '/picture">'+'<h4>' + name + '</h4><p>' + short_post +'....</p></a></li>';

I then have,

 $(newsfeedposts).append(markup);

$(newsfeedposts).trigger("create");

however after that when i call the

$(newsfeedposts).listview("refresh");

I get a type error: TypeError: $(...).listview is not a function

my html div tag is this

  <div data-role="content"> <div class ="post">
    <ul data-role="listview"  class="ui-listview" id="newsfeedposts" data-divider-theme="b" data-theme="a" data-overlay-theme="a" data-autodividers="true" data-inset="true">
</ul>
  </div>

please let me know if you identify what Im doing wrong.This has been taking so longg...


回答1:


You're not using jQuery-selector the right way. To target an element with an id, use $('#element_id') and for an element with a class $('.element_class'). So, your selection should be as below.

$('#newsfeedposts').append(markup);

and then

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


来源:https://stackoverflow.com/questions/17323981/listview-is-not-a-function-error-when-creating-a-dynamic-listview-in-jquery-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!