以下代码中“goods”是一个商品集合对象,测试过goods对象没有问题,下面代码可以遍历并输出第一商品信息,但循环到第二次就会报错。帮我看一下是什么原因。谢谢!$(function(){
$.each(goods,function(index,obj){
$.each(obj,function(pro,val){     //循环到第二个商品时报错的位置:对象不支持此属性或方法
document.write(pro+":"+val+"<br/>");
});
document.write("<hr/>");
});
});

解决方案 »

  1.   


    $(function(){ 
    $.each(goods,function(index,obj){ 
    $.each(index,function(pro,val){ 
    document.write(pro+":"+val+" <br/>"); 
    }); 
    document.write(" <hr/>"); 
    }); 
    });
      

  2.   

    代码应该没问题。你可以把goods数据打印出来瞅瞅吗?
      

  3.   

    [{"cId":2,"cName":"\u767d\u841d\u535c","cType":"1","growthCycle":"36000","maturingTime":"1","expect":272,"output":"16","sale":"17","price":"125","cLevel":"0","cropExp":"15","vip":"1"},{"cId":3,"cName":"\u80e1\u841d\u535c","cType":"1","growthCycle":"46800","maturingTime":"1","expect":357,"output":"17","sale":"21","price":"163","cLevel":"0","cropExp":"18","vip":"1"},{"cId":4,"cName":"\u7389\u7c73","cType":"1","growthCycle":"50400","maturingTime":"1","expect":391,"output":"17","sale":"23","price":"175","cLevel":"3","cropExp":"19","vip":"1"},{"cId":5,"cName":"\u571f\u8c46","cType":"1","growthCycle":"54000","maturingTime":"1","expect":432,"output":"18","sale":"24","price":"188","cLevel":"4","cropExp":"20","vip":"1"},{"cId":6,"cName":"\u8304\u5b50","cType":"1","growthCycle":"57600","maturingTime":"1","expect":500,"output":"20","sale":"25","price":"237","cLevel":"5","cropExp":"21","vip":"1"},{"cId":7,"cName":"\u756a\u8304","cType":"1","growthCycle":"61200","maturingTime":"1","expect":546,"output":"21","sale":"26","price":"251","cLevel":"6","cropExp":"22","vip":"1"},{"cId":8,"cName":"\u8c4c\u8c46","cType":"1","growthCycle":"64800","maturingTime":"1","expect":594,"output":"22","sale":"27","price":"266","cLevel":"7","cropExp":"23","vip":"1"},{"cId":9,"cName":"\u8fa3\u6912","cType":"1","growthCycle":"72000","maturingTime":"1","expect":672,"output":"24","sale":"28","price":"296","cLevel":"8","cropExp":"25","vip":"1"},{"cId":10,"cName":"\u5357\u74dc","cType":"1","growthCycle":"79200","maturingTime":"1","expect":750,"output":"25","sale":"30","price":"325","cLevel":"9","cropExp":"27","vip":"1"},{"cId":11,"cName":"\u82f9\u679c","cType":"1","growthCycle":"75600","maturingTime":"2","expect":1104,"output":"23","sale":"24","price":"578","cLevel":"10","cropExp":"18","vip":"1"},{"cId":1,"cName":"\u8349\u8393","cType":"1","growthCycle":"86400","maturingTime":"2","expect":1296,"output":"24","sale":"27","price":"605","cLevel":"10","cropExp":"20","vip":"1"},{"cId":14,"cName":"\u897f\u74dc","cType":"1","growthCycle":"100800","maturingTime":"2","expect":1566,"output":"27","sale":"29","price":"708","cLevel":"11","cropExp":"23","vip":"1"},{"cId":15,"cName":"\u9999\u8549","cType":"1","growthCycle":"111600","maturingTime":"2","expect":1856,"output":"29","sale":"32","price":"900","cLevel":"12","cropExp":"25","vip":"1"},{"cId":18,"cName":"\u6843\u5b50","cType":"1","growthCycle":"151200","maturingTime":"2","expect":2560,"output":"32","sale":"40","price":"1200","cLevel":"13","cropExp":"33","vip":"1"},{"cId":19,"cName":"\u6a59\u5b50","cType":"1","growthCycle":"133200","maturingTime":"3","expect":3198,"output":"26","sale":"41","price":"1587","cLevel":"14","cropExp":"25","vip":"1"},{"cId":13,"cName":"\u8461\u8404","cType":"1","growthCycle":"165600","maturingTime":"3","expect":4089,"output":"29","sale":47,"price":"1978","cLevel":"15","cropExp":"30","vip":"1"},{"cId":23,"cName":"\u77f3\u69b4","cType":"1","growthCycle":"187200","maturingTime":"3","expect":4860,"output":"30","sale":"54","price":"2425","cLevel":"16","cropExp":"34","vip":"1"},{"cId":26,"cName":"\u67da\u5b50","cType":"1","growthCycle":"219600","maturingTime":"3","expect":5742,"output":"33","sale":"58","price":"2855","cLevel":"17","cropExp":"39","vip":null},{"cId":27,"cName":"\u83e0\u841d","cType":"1","growthCycle":"230400","maturingTime":"3","expect":6510,"output":"35","sale":"62","price":"3480","cLevel":"18","cropExp":"40","vip":null},{"cId":29,"cName":"\u6930\u5b50","cType":"1","growthCycle":"198000","maturingTime":"4","expect":7020,"output":"27","sale":"65","price":"3720","cLevel":"19","cropExp":"32","vip":null},{"cId":31,"cName":"\u846b\u82a6","cType":"1","growthCycle":"219600","maturingTime":"4","expect":8520,"output":"30","sale":"71","price":"4742","cLevel":"20","cropExp":"36","vip":null},{"cId":33,"cName":"\u706b\u9f99\u679c","cType":"1","growthCycle":"252000","maturingTime":"4","expect":9856,"output":"32","sale":"77","price":"5356","cLevel":"21","cropExp":"41","vip":null},{"cId":34,"cName":"\u6a31\u6843","cType":"1","growthCycle":"259200","maturingTime":"4","expect":10296,"output":"33","sale":"78","price":"5527","cLevel":"22","cropExp":"42","vip":null},{"cId":35,"cName":"\u8354\u679d","cType":"1","growthCycle":"277200","maturingTime":"4","expect":11696,"output":"34","sale":"86","price":"6588","cLevel":"23","cropExp":"44","vip":null},{"cId":40,"cName":"\u7267\u8349","cType":"1","growthCycle":"28800","maturingTime":"1","expect":150,"output":"25","sale":"6","price":"120","cLevel":"0","cropExp":"10","vip":null},{"cId":38,"cName":"\u6728\u74dc","cType":1,"growthCycle":165600,"maturingTime":5,"expect":11200,"output":28,"sale":80,"price":6975,"cLevel":24,"cropExp":26,"vip":null},{"cId":39,"cName":"\u6768\u6843","cType":1,"growthCycle":165600,"maturingTime":5,"expect":11890,"output":29,"sale":82,"price":7576,"cLevel":25,"cropExp":27,"vip":null},{"cId":41,"cName":"\u7ea2\u73ab\u7470","cType":1,"growthCycle":64800,"maturingTime":1,"expect":594,"output":22,"sale":27,"price":266,"cLevel":7,"cropExp":23,"vip":null}];
      

  4.   

    看看循环到第二个商品时obj是什么东西啊
      

  5.   

    找到问题了,我在body中写的代码,不用$(function(){});谢谢大家