1

名前、コード、およびカテゴリを取得するための私のjqueryコード:

     $(req.responseText).find("Table").each(function(i) {
              var item = $(this),
              name = item.find('Name').text(),
              code = item.find('Code').text(),
              catg = item.find('Category').text();                    

                 var $content = $('<li><a href="#"><img src="../../img/album-bb.jpg"><h3>Name: '+ name + '</h3><p>Code: '+ code + '</p><p>Category: '+ catg + '</p></a><a href="#purchase" data-rel="popup" data-position-to="window" data-transition="pop">Add to favorites</a></li>');                              
                 $('#RecipeList').append($content).listview('refresh');



      });

これは私のXMLのサンプル応答です:

<Table diffgr:id="Table1" msdata:rowOrder="0">
    <Code>106377</Code>
    <Name>Blackened red snapper</Name>
    <Category>123</Category>
    <Yield>4</Yield>
    <YieldUnit/>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
    <Code>303570</Code>
    <Name>Celery soup</Name>
    <Category>123</Category>
    <Yield>1</Yield>
    <YieldUnit/>
</Table>
<Table diffgr:id="Table3" msdata:rowOrder="2">
    <Code>303675</Code>
    <Name>Challah French Toast</Name>
    <Category>123</Category>
    <Yield>6</Yield>
    <YieldUnit/>
   </Table>

リストビューの出力は次のとおりです。

Name: Blackened red snapperCelerySoupChallah French toast
Code: 106377303570303675
Category: 123123123

別のリストビューに入れる方法は?..そのappend.Thanksのとき

4

2 に答える 2

1

これを試して:

var ni = 0;
var ci = 0;
var cati = 0;
var NameArr = new Array();
var CodeArr = new Array();
var CatArr  = new Array();

$(req.responseText).find('Name').each(function () {
  NameArr[ni] = $(this).text();
  ni++;
}

$(req.responseText).find('Code').each(function () {
  CodeArr[ci] = $(this).text();
  ci++;
}

$(req.responseText).find('Category').each(function () {
  CatArr[cati] = $(this).text();
  cati++;
}

for(var i=0; i<NameArr.length; i++){
    var $content = $('<li><a href="#"><img src="../../img/album-bb.jpg"><h3>Name: '+ NameArr[i] + '</h3><p>Code: '+ CodeArr[i]+ '</p><p>Category: '+ CatArr[i]+ '</p></a><a href="#purchase" data-rel="popup" data-position-to="window" data-transition="pop">Add to favorites</a></li>');                              
    $('#RecipeList').append($content).listview('refresh');
}
于 2013-04-25T08:09:03.323 に答える