2013-04-29 38 views
0

有一部分我的XML响应,我需要放在不同的列表视图与编号。 这是响应单独列表视图

<Note> 
Cook pasta according to directions, chill in ice water, drain.¶Blanch broccoli in boiling water, chill in ice water, drain.¶Use ½ soy sauce to season the chicken, heat oil in no stick pan, brown chicken, and reduce heat and finish cooking.¶Don"t overcook! Slice chicken into 1" strips, turn and cut into ¼" pieces, place into bowl with other ingredients except dressing and soy sauce.¶Mix remainder of soy sauce into dressing and pour over pasta, chicken, and vegetables.¶Toss gently and serve immediately.¶You might like to leave the pasta, chicken, broccoli un-chilled and serve it semi-warm 
</Note> 

的“¶”是每个程序的分离 - 符号。我怎样才能追加这个列表视图? seperately ..我需要一些帮助,谢谢


这是我的代码。不工作

$(req.responseText).find('NewDataSet').each(function(){ 
       var split = $(this).find('Note').text(); 
        var lines = split.split('¶'); 
        $.each(lines, function(key, line) { 
        $('#RecipeProc').append('<li><a href="#">' + line + '</a></li>'); 
         $('#RecipeProc').listview('refresh'); 
        }); 


       }); 

回答

1

工作例如:http://jsfiddle.net/Gajotres/Z7uxZ/

HTML:

<!DOCTYPE html> 
<html> 
    <head> 
     <title>jQM Complex Demo</title> 
     <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/> 
     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" /> 
     <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>  
    </head> 
    <body> 
     <div data-role="page" id="index"> 
      <div data-theme="a" data-role="header"> 
       <h3> 
        First Page 
       </h3> 
       <a href="#second" class="ui-btn-right">Next</a> 
      </div> 

      <div data-role="content"> 
       <ul data-role="listview" data-theme="a" id="custom-listview"> 

       </ul> 
      </div> 

      <div data-theme="a" data-role="footer" data-position="fixed"> 

      </div> 
     </div>  
    </body> 
</html> 

的Javascript:

$(document).on('pagebeforeshow', '#index', function(){  
    var split = 'Cook pasta according to directions, chill in ice water, drain.¶Blanch broccoli in boiling water, chill in ice water, drain.¶Use ½ soy sauce to season the chicken, heat oil in no stick pan, brown chicken, and reduce heat and finish cooking.¶Don"t overcook! Slice chicken into 1" strips, turn and cut into ¼" pieces, place into bowl with other ingredients except dressing and soy sauce.¶Mix remainder of soy sauce into dressing and pour over pasta, chicken, and vegetables.¶Toss gently and serve immediately.¶You maight like to leave the pasta, chicken, broccoli un-chilled and serve it semi-warm'; 

    var lines = split.split('¶'); 
    $.each(lines, function(key, line) { 
     $('#custom-listview').append('<li><a href="#">' + line + '</a></li>'); 
    }); 
    $('#custom-listview').listview('refresh'); 
}); 

编辑:

要调试你的应用程序:

  1. 首先检查您的变量分裂有一个值

    var split = $(this).find('Note').text(); 
    alert(split); // or console.log(split); 
    
  2. 如果点1是正确的,那么检查刺痛成功splited:

    var lines = split.split('¶'); 
    alert(lines.length); 
    
+0

sir pleas e看到我的代码。它不工作即时通讯基于您的代码 – 2013-04-29 08:32:57

+0

空是警报消息。 – 2013-04-29 08:46:53

+0

在什么时候? 1或2? – Gajotres 2013-04-29 08:47:52

相关问题