【发布时间】:2014-01-17 16:33:17
【问题描述】:
我浏览了有关此问题的旧帖子,但没有找到解决问题的方法。
我的计算机上有 2 个 REST 服务,1 个用于登录,2 个用于发送列表项。
我可以使用登录网络服务进行连接和登录。 我的第二个 Web 服务在登录后被调用,它以以下形式提供 JSON 数据..
[{"oid":101,"summary":"这是我的第一个订单"},{"oid":102,"summary":"这是第二个订单"}]
我想解析这个 JSON 字符串并创建一个“oid”列表,然后如果我点击第一项,我应该会在新页面上看到“摘要”。当我点击后退按钮时,我想再次调用该服务以刷新列表。
这是我尝试过的代码。
<script>
$.getJSON('http://192.168.2.36:8080/phoneservlet/getOrders', function(data){
var output = '';
$.each(data, function(index, value){
//add each value to the output buffer (we also have access to the other properties of this object: id, start, and end)
output += '<li>'+ value.oid +'</li>';
});
//now append the buffered output to the listview and either refresh the listview or create it (meaning have jQuery Mobile style the list)
$('#your-orders').append(output).listview('refresh');//or if the listview has yet to be initialized, use `.trigger('create');` instead of `.listview('refresh');`
});
</script>
这是for列表
<div data-role="page" id="currentorders">
<div data-role="content" id="data">
<ul data-role="listview" id="your-orders" data-divider-theme="b" data-inset="true">List of Orders</ul>
</div>
问题是我的列表没有被填充。我看到一个空列表,只有我的列表标题是“订单列表”
我是 jquery 的新手,所以我还没有弄清楚如何在新页面上显示摘要..
【问题讨论】:
标签: json web-services jquery-mobile web cordova