Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

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

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...