问题
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