0

这是我的 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 ?任何帮助将不胜感激。

4

2 回答 2

1

你为什么不这样做?

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

于 2013-09-04T05:48:42.133 回答
0

改变

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');
            }
        });
于 2013-09-04T05:44:25.360 回答