2013-05-30 20 views
0

我想從xml文件中製作基於jquery的搜索引擎....現在我需要獲取x和y之間的價格範圍內的所有屬性....我我正在使用過濾器功能,但我做錯了什麼或缺少的東西。爲了測試我比較我的XML記錄的價值,下面的代碼應該只帶來一個記錄,但不是......非常感謝提前!jQuery的篩選記錄,其範圍介於x和y之間沒有

function searchProperties() { 

      $.ajax({ 
       type: "GET", 
       url: "propertyXMLData.xml", 
       dataType: "xml", 
       success: function (xml) { 

        $(xml).find('property').each(function() { 

         x_priceask.push($(this).find('priceask').filter(function() { 
          return $(this).text() == 229,995; 

         })); 

       }); //end Ajax call 

        alert(x_priceask.length); 

        for (i = 0; i <= (x_priceask.length - 1); i++) 
        { 
         alert(x_priceask[i].text()); 
        } 
       }, 
       error: function() { 
        alert("An error occurred while processing XML file."); 
       } 
      }); 
     } 

我已經嘗試過,但仍然不工作!

$(xml).find('property').each(function() { 

x_priceask.push($(this).find('priceask').filter(function (index) { 
     var value = parseInt($(this).val()); 
     return value==229,995; 

         })); 
+2

'$回報(本)的.text()== 229995;'是不是一個有效的語法,它應該是'$返回(本)的.text()== '229,995';' –

+0

你也可以分享迴應xml –

+0

是的,你是對的......這是非常愚蠢的錯誤... – khurram

回答

0

嘗試

function searchProperties() { 

    $.ajax({ 
     type: "GET", 
     url: "propertyXMLData.xml", 
     dataType: "xml", 
     success: function (xml) { 

      var x_priceask = $(xml).find('property').filter(function(){ 
       return $(this).find('priceask').text() == '229,995'; 
      }) 

      alert(x_priceask.length); 

      for (i = 0; i <= (x_priceask.length - 1); i++) 
      { 
       alert(x_priceask[i].text()); 
      } 
     }, 
     error: function() { 
      alert("An error occurred while processing XML file."); 
     } 
    }); 
} 
相關問題