在 jquery mobile 中创建动态列表视图时,.listview() 不是函数错误 [英] .listview() is not a function error when creating a dynamic listview in jquery mobile

查看:21
本文介绍了在 jquery mobile 中创建动态列表视图时,.listview() 不是函数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查询 facebook api 后,我试图在 jquery mobile 中创建一个动态列表视图,以检索用户的新闻提要.这是我标记的一部分:

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

'+ 名称 + '</h4><p>'+ short_post +'....</p></a></li>';

然后我有,

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

但是在那之后当我打电话给

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

我收到一个类型错误:TypeError: $(...).listview is not a function

我的 html div 标签是这个

 

<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="真" 数据插入="真">

如果你发现我做错了什么,请告诉我.这已经花了很长时间......

解决方案

您没有以正确的方式使用 jQuery 选择器.要定位具有 id 的元素,请使用 $('#element_id') 和具有类 $('.element_class') 的元素.因此,您的选择应如下所示.

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

然后

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

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

解决方案

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

这篇关于在 jquery mobile 中创建动态列表视图时,.listview() 不是函数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆