且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不能产生通过jQuery Mobile的使用JSON响应的动态列表视图?

更新时间:2023-01-16 15:26:07

你为什么不这样做?这样

  $。每个(respPrice.Value,功能(指数值){
      如果(respPrice.VarietyID == 0){
         警报('没有产品清单潜艇发现');
      }其他{       编制者= value.subsID;
       物质= value.Subs;
       minPrice = value.MinPrice;
       maxPrice = value.MaxPrice;
       $ respPrice ='<李班=UI-BTN UI的BTN-图标右UI丽有箭头的UI立UI的最后一个孩子UI的BTN-UP-E>' +物质+ minPrice +' - '+ maxPrice +'< /李>';       //这里追加
       $('#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/