0

<product>从文本输入中接收“天”后,如何<availabilities>使用 jQuery 仅从同一日期显示?也许使用.siblings()?

<?xml version='1.0' encoding='iso-8859-15'?>
<timetable>
  <date>
    <day>22-01-2013</day>
    <availabilities>
      <availability>
        <starttime>10:00</starttime>
        <endtime>13:00</endtime>
        <startplace>Funchal</startplace>
        <endplace>Funchal</endplace>
        <resource>Excursões na Madeira</resource>
        <idstartplace>18</idstartplace>
        <idendplace>18</idendplace>
        <idperiodoconsumo>13289</idperiodoconsumo>
        <idproduct>23</idproduct>
        <product>EXC_SANT</product>
        <idtimeperiod>11523</idtimeperiod>
        <idavailability>3561</idavailability>
      </availability>
      <availability>
        <starttime>10:00</starttime>
        <endtime>13:00</endtime>
        <startplace>Funchal</startplace>
        <endplace>Funchal</endplace>
        <resource>Excursões na Madeira</resource>
        <idstartplace>18</idstartplace>
        <idendplace>18</idendplace>
        <idperiodoconsumo>13290</idperiodoconsumo>
        <idproduct>33</idproduct>
        <product>foot</product>
        <idtimeperiod>11524</idtimeperiod>
        <idavailability>3593</idavailability>
      </availability>
      <availability>
        <starttime>10:00</starttime>
        <endtime>13:00</endtime>
        <startplace>Funchal</startplace>
        <endplace>Funchal</endplace>
        <resource>Excursões na Madeira</resource>
        <idstartplace>18</idstartplace>
        <idendplace>18</idendplace>
        <idperiodoconsumo>13289</idperiodoconsumo>
        <idproduct>22</idproduct>
        <product>VLT_ILHA</product>
        <idtimeperiod>11523</idtimeperiod>
        <idavailability>3561</idavailability>
      </availability>
    </availabilities>
  </date>
  <date>
      ...
      </date> 
...

这是我的成功:功能:

function parseStuff(data){
    $(data).find('date').each(function(){
        var day = $(this).find('day').text();

        if (day==decodeURI(iHash[3])){
            alert('Date matches!');
        }
    });
}

我会很感激一些帮助,我不知道该怎么做.. :|

4

2 回答 2

1

试试这个:

var product = $(this).find('product').text();

我想你必须把这个放在这里:

if (day==decodeURI(iHash[3])){
  var product = $(this).find('product').text();
  alert('Date matches!');
}
于 2013-02-14T17:08:07.093 回答
0

这应该适合你:

function parseStuff(data,toBeMatchedDate){

    productList=array();

    $(data).find('date').each(function(){


        var day = $(this).find('day').text();

        if (day==decodeURI(iHash[3]) && day==toBeMatchedDate)   //if date is matched
        {

             xmlProdcutList=$(this).find('product'); //all the products associated with this date


             $.each(function(i,thisProduct){
                         productList.push(thisProduct.text()); //store in the main array
               });

return productList;


        }
    });
}
于 2013-02-14T17:27:05.643 回答