ajax获得json对象数组 循环输出数据的方法

如下所示:

var obj=
 [{id: 1, pId: 0, name: "采购商品", open: true}, {id: 2, pId: 1, name: "雨伞2", open: true}, {id: 2, pId: 1, name: "雨伞2", open: true}, {id: 2, pId: 1, name: "雨伞2", open: true}];
var x='';
  $.each(obj, function (n, value) {
  // alert(n + ' ' + value);
   var trs = "";
   trs += "<tr><td>" + value.name + "</td> <td>" + value.id + "</td></tr>";
   x += trs;
  });

  $("#project").append(x);

ajax获得json对象数组 循环输出数据的方法

相关推荐