我发送了一个JSONP请求,结果集中有三种方法。
问题出在第一个函数执行后,其余的不是。
function syncData(jsonData){
alert('1');
getUnreadNotifications(jsonData.getUnreadNotifications);
alert('2');
getActiveCL(jsonData.getActiveCL);
alert('3');
getActiveCLI(jsonData.getActiveCLI);
}
它只会提醒1.然后停止。以下是功能......我做错了什么?
function getActiveCL(jsonData2){
var list =$('#ul-cl');
list.empty();
var htmldata = '';
jQuery.each(jsonData2, function() {
htmldata += '<li data-theme="a" class="ui-btn ui-btn-up-b ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-count ui-corner-top"><div class="ui-btn-inner ui-li"><div class="ui-btn-text"><a href="#consideration-list-id-' + this.id + '" class="ui-link-inherit">Table ' + this.table + ' - ' + this.guest_name + ' ' + this.created + ' <span class="ui-li-count ui-btn-up-c ui-btn-corner-all">' + this.items + '</span></a></div><span class="ui-icon ui-icon-arrow-r ui-icon-shadow"></span></div></li>';
});
list.append(htmldata);
list.listview();
list.listview('refresh');
$('a[href="#consideration-list-listing"] .ui-li-count').html(jsonData2.length);
}
function getActiveCLI(jsonData){
var lists =$('[id^="ul-consideration-list-id-"]');
lists.empty();
alert(jsonData);
jQuery.each(jsonData, function() {
var list = $('#ui-consideration-list-id-'+ this.cl_id);
//timeElapsed = elapsedpretty(this.created);
alert(list.size());
var htmldata = '<li data-theme="a" class="ui-btn ui-btn-up-b ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-count ui-corner-top"><div class="ui-btn-inner ui-li"><div class="ui-btn-text"><a href="#item-id-' + this.item_id + '" class="ui-link-inherit">' + this.name + '</a></div><span class="ui-icon ui-icon-info ui-icon-shadow"></span></div></li>';
list.append(htmldata);
});
lists.listview();
lists.listview('refresh');
}
function getUnreadNotifications(jsonData){
// Build Lists
var appendData = '';
var list = $('#message-ul');
var lastID = 0;
var messageCount = [];
var currentVal = parseInt($('.nav a[href="#message-listing"] .ui-li-count').html());
jQuery.each(jsonData, function() {
appendData +='<li id="mid-'+this.id+'" data-theme="a" class="ui-btn ui-btn-up-b ui-btn-icon-right ui-li-has-arrow ui-li ui-li-has-count ui-corner-top ui-li-static ui-body-a" ><span class="ui-icon ui-icon-alert ui-icon-shadow"></span><div class="ui-btn-inner ui-li ui-li-static ui-body-a"><div class="ui-btn-text">Table '+this.table+' - '+this.created+'</div></div></li>';
lastID = this.id;
});
// Prepend new messages
list.prepend($(appendData).hide()).children().slideDown();
$('a[href="#message-listing"] .ui-li-count').html(currentVal + jsonData.length);
// Set last checked id
if(lastID !== 0) localStorage.setItem('last_message_id', lastID);
list.listview();
list.listview('refresh');
}
最后是JSON。在jsonlint中测试了所有内容并验证:
syncData({
"getUnreadNotifications": [
{
"id": "98",
"message_type_id": "2",
"visit_id": "82",
"active": "1",
"created": "2011-10-07 13:42:21",
"table": "2",
"rvc_id": "2",
"zone": "2",
"seat": "1",
"guest_name": "Foster Test"
},
{
"id": "100",
"message_type_id": "4",
"visit_id": "82",
"active": "1",
"created": "2011-10-07 16:11:10",
"table": "2",
"rvc_id": "2",
"zone": "2",
"seat": "1",
"guest_name": "Foster Test"
},
{
"id": "101",
"message_type_id": "5",
"visit_id": "82",
"active": "1",
"created": "2011-10-07 16:11:10",
"table": "2",
"rvc_id": "2",
"zone": "2",
"seat": "1",
"guest_name": "Foster Test"
},
{
"id": "102",
"message_type_id": "3",
"visit_id": "82",
"active": "1",
"created": "2011-10-07 16:11:11",
"table": "2",
"rvc_id": "2",
"zone": "2",
"seat": "1",
"guest_name": "Foster Test"
},
{
"id": "103",
"message_type_id": "2",
"visit_id": "82",
"active": "1",
"created": "2011-10-08 13:22:57",
"table": "2",
"rvc_id": "2",
"zone": "2",
"seat": "1",
"guest_name": "Foster Test"
},
{
"id": "104",
"message_type_id": "4",
"visit_id": "82",
"active": "1",
"created": "2011-10-08 13:22:57",
"table": "2",
"rvc_id": "2",
"zone": "2",
"seat": "1",
"guest_name": "Foster Test"
},
{
"id": "105",
"message_type_id": "2",
"visit_id": "82",
"active": "1",
"created": "2011-10-08 13:23:08",
"table": "2",
"rvc_id": "2",
"zone": "2",
"seat": "1",
"guest_name": "Foster Test"
}
],
"getActiveCL": [
{
"id": "9",
"visit_id": "82",
"created": 1317949631,
"items": "6",
"table": "2",
"guest_name": "Foster Test"
}
],
"getActiveCLI": [
{
"table": "2",
"cl_id": "9",
"item_id": "100010",
"price": "4300",
"name": "Anakena"
},
{
"table": "2",
"cl_id": "9",
"item_id": "18027",
"price": "5500",
"name": "Chicken Shashlik"
},
{
"table": "2",
"cl_id": "9",
"item_id": "18016",
"price": "3500",
"name": "Chicken Steak Burger"
},
{
"table": "2",
"cl_id": "9",
"item_id": "18018",
"price": "3700",
"name": "Lamb Sausage Masala Pizza"
},
{
"table": "2",
"cl_id": "9",
"item_id": "100370",
"price": "4300",
"name": "Lamole di Lamole - Chianti Classico D.O.C.G"
},
{
"table": "2",
"cl_id": "9",
"item_id": "100460",
"price": "4300",
"name": "Morande Grand Reserve"
}
]
});
答案 0 :(得分:1)
我做错了什么?
不查看JS控制台中的错误日志以找出抛出的异常...
答案 1 :(得分:1)
TypeError
。你确定你使用的是jqm的最新版本吗?
您正在调用list.listview();
,但list.listview
可能未定义。因此,尝试将undefined作为函数调用会引发错误。一旦解释器遇到错误,它就会停止执行,因此不会调用脚本的其余部分,包括警报。