不能产生通过jQuery Mobile的使用JSON响应的动态列表视图? [英] unable to generate dynamic listview through JQuery Mobile with JSON response?

查看:172
本文介绍了不能产生通过jQuery Mobile的使用JSON响应的动态列表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的JSON响应格式: -

<$p$p><$c$c>{\"Value\":[{\"ID\":\"1\",\"productID\":\"10\",\"subsID\":\"9\",\"MinPrice\":\"500\",\"MaxPrice\":\"50000\",\"Subs\":\"xyz100\"}]}

下面是我的.js code: -

 函数PRODUCTURL(URL){
    警报(URL);
    $阿贾克斯({
        网址:网址,
        键入:GET,
        数据类型:JSON
        的contentType:应用/ JSON
        异步:假的,
        成功:函数(MSG){
            VAR respPrice = msg.Value;
            $。每个(respPrice,功能(指数值){
                如果(value.VarietyID == 0){
                    警报('没有产品清单潜艇发现');
                }其他{                    编制者= value.subsID;
                    物质= value.subs;
                    minPrice = value.MinPrice;
                    maxPrice = value.MaxPrice;
                    respPrice + ='&LT;李班=UI-BTN UI的BTN-图标右UI丽有箭头的UI立UI的最后一个孩子UI的BTN-UP-E&GT;' +物质+ minPrice +' - '+ maxPrice +'&LT; /李&GT;';
                    };                    }
                });
             $('#productList的')追加(respPrice).listview('刷新');                },
            错误:功能(E){
                的console.log(e.message);
                警报('错误Occoured')​​;
            }
        });
}

请告诉我修改我需要做的就是正确的一代的ListView?任何帮助将大大appriciated。


解决方案

你为什么不这样做?这样

  $。每个(respPrice.Value,功能(指数值){
      如果(respPrice.VarietyID == 0){
         警报('没有产品清单潜艇发现');
      }其他{       编制者= value.subsID;
       物质= value.Subs;
       minPrice = value.MinPrice;
       maxPrice = value.MaxPrice;
       $ respPrice ='&LT;李班=UI-BTN UI的BTN-图标右UI丽有箭头的UI立UI的最后一个孩子UI的BTN-UP-E&GT;' +物质+ minPrice +' - '+ maxPrice +'&LT; /李&GT;';       //这里追加
       $('#productList的')追加($ respPrice)。
     }
 }); //当全部完成,$。每个()后刷新列表视图
 $('#productList的')的ListView('刷新');

这里是一个小提琴: http://jsfiddle.net/REthD/19/

Here is my Json response format :-

{"Value":[{"ID":"1","productID":"10","subsID":"9","MinPrice":"500","MaxPrice":"50000","Subs":"xyz100"}]}

Here is my .js code :-

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

Whats modifications do i need to do to get the proper generation of listview ? Any help would be greatly appriciated.

解决方案

why dont you do this way??

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

here is a fiddle: http://jsfiddle.net/REthD/19/

这篇关于不能产生通过jQuery Mobile的使用JSON响应的动态列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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