考虑这个 json 对象:
[{"data":{"ID":"3","Category":"Career"}},{"data":{"ID":"5","Category":"Emotions"}},{"data":{"ID":"1","Category":"Finance"}},{"data":{"ID":"2","Category":"Health"}},{"data":{"ID":"6","Category":"Legacy"}},{"data":{"ID":"4","Category":"Relationships"}}]  
并考虑此客户端代码:
$(function (){ 
 $.ajax({                                      
  url: 'category.php',                         
  data: "",                        
   dataType: 'json',                      
  success: function(data)         
  {
     var output = '';
      $.each( data, function( key, obj) {
      $.each( obj, function( index, item) {
        //console.log(index+ ": " + item);
        url = "goal.php?catID=" + item.ID;
        output = '<li><a>' + item.Category+ '</a></li>';
        href = $('a').attr("href",url); $('a').append(href);
        $('#listview').append(output).listview('refresh');
       });
   });
   } 
});  }); 
<div data-role="page" id="home">
<div data-role="header"><h1>My Goals</h1></div>
<div data-role="listview" data-autodividers="true" data-inset="true">
  <ul data-role="listview" id="listview">    
  </ul>
</div>
我在 JQuery mobile 中的第一次尝试,我试图遍历 JSON 并输出带有链接的类别 -
我几乎成功了,但它只是在 url 上附加最后一条记录 item.ID?
有人可以帮忙吗?
谢谢