无法使用JSON响应通过JQuery Mobile生成动态列表视图
unable to generate dynamic listview through JQuery Mobile with JSON response?
这是我的Json响应格式:-
{"Value":[{"ID":"1","productID":"10","subsID":"9","MinPrice":"500","MaxPrice":"50000","Subs":"xyz100"}]}
这是我的.js代码:-
function productURL(url) {
alert(url);
$.ajax({
url: url,
type : "GET",
dataType : "json",
contentType: "application/json",
async : false,
success : function(msg) {
var respPrice = msg.Value;
$.each(respPrice, function(index, value) {
if(value.VarietyID == 0) {
alert('No product subs list found');
} else {
subsId = value.subsID;
substance = value.subs;
minPrice = value.MinPrice;
maxPrice = value.MaxPrice;
respPrice += '<li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-last-child ui-btn-up-e">' + substance + minPrice + '-' + maxPrice + '</li>';
};
}
});
$('#productList').append(respPrice).listview('refresh');
},
error : function(e) {
console.log(e.message);
alert('Error Occoured');
}
});
}
我需要做哪些修改才能正确生成listview?任何帮助都将不胜感激。
为什么不这样做??
$.each(respPrice.Value, function(index, value) {
if(respPrice.VarietyID == 0) {
alert('No product subs list found');
} else {
subsId = value.subsID;
substance = value.Subs;
minPrice = value.MinPrice;
maxPrice = value.MaxPrice;
$respPrice = '<li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-last-child ui-btn-up-e">' + substance + minPrice + '-' + maxPrice + '</li>';
// append here
$('#productList').append($respPrice);
}
});
// and when all done, after $.each() refresh the listview
$('#productList').listview('refresh');
这是一把小提琴:http://jsfiddle.net/REthD/19/
更改
success : function(msg) {
var respPrice = "";
$.each(respPrice, function(index, value) {
if(value.VarietyID == 0) {
alert('No product subs list found');
} else {
subsId = value.subsID;
substance = value.subs;
minPrice = value.MinPrice;
maxPrice = value.MaxPrice;
respPrice += '<li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-last-child ui-btn-up-e">' + substance + minPrice + '-' + maxPrice + '</li>';
}
}
$('#productList').append(respPrice).listview('refresh');
});
},
error : function(e) {
console.log(e.message);
alert('Error Occoured');
}
});
相关文章:
- 通过在Dojo mobile ViewController.openExternalView中动态更改打开同一外部视图的
- UIWebview赢得't通过基本身份验证加载动态加载的资源(通过jQuery mobile)
- 根据手机上是否存在文件,在jQuery mobile中动态填充列表视图
- 使用PhoneGap和jQuery Mobile在android设备上显示动态列表视图
- 如何在jquery mobile中使用json文件创建动态下拉菜单
- 将动态feild数据存储到jquery-mobile和php-mysql中的数据库中
- jQuery mobile-动态更改ui页面背景颜色
- jQuery Mobile:动态表单创建显示本机控件与jQuery Mobile插件控件
- jquery-mobile动态扩展列表视图;不起作用
- 带滚动选项的Jquery Mobile动态列表视图
- 使用Jquery Mobile动态选择cordova应用程序的第一个屏幕
- 如何使用jQuery Mobile动态添加侧面板菜单项并保持所有CSS样式
- jQuery Mobile动态改变按钮颜色
- 如何使用jQuery Mobile动态创建按钮
- JQuery Mobile:动态加载的页面源在DOM中仍然可用,即使在更改页面之后
- 是否可以使用jQuery Mobile动态创建元素?
- 使用jQuery Mobile动态添加DIV后刷新
- Jquery Mobile动态创建范围变化事件不触发
- jQuery Mobile:动态创建的元素没有点击事件
- jQuery Mobile:动态创建网格类型按钮