jQuery中$ .each()的问题

我想通过jQuery.each和数据hotel_id从数组中追加一些,每个hotel_id是4,这个循环$.each(data[0].hotel_id,... }); 在自己内部运行4次内容,如果有数据库行或者插入residence_u hotel_idhotel_id 3次(每次都有3次,而不是4次(如hotel_id )),运行以下代码时,此代码没有错误jus不行。 如果我删除代码$.each(info_ru.units,... });$.each(info_rp.start_date,... }); 它工作:如何解决它?

查看完整的我的js代码:[ http://pastebin.com/jBWEDZrN ] [1]

这是我在ajax调用中的js代码的摘要( url: 'get_gr', ):

 $.each(data[0].hotel_id, function (index, value) { var $li = $('
  • '); var $tooltip = $('
    ').appendTo($li); $li.appendTo('#residence_name'); var info_ru = data[0].residence_u[index]; $.each(info_ru.units, function (index, value) { $tooltip.append(value + ' & ' + info_ru.extra[index] + ' & ' + info_ru.price[index] + '
    '); }); var info_rp = data[0].residence_p[index]; $.each(info_rp.start_date, function (index, value) { $tooltip.append(value + ' & ' + info_rp.end_date[index] + ' & ' + info_rp.price_change[index] + '
    '); }); tool_tip() });

    这是输出php代码( url: 'get_gr', ):

     [{ "guide": null, "hotel_id": [{ "hotel_id": ["1"] }, { "hotel_id": ["2"] }, { "hotel_id": ["3"] }, { "hotel_id": ["4"] }], "residence_u": [{ "units": ["hello", "how", "what"], "extra": ["11", "22", "33"], "price": ["1,111,111", "2,222,222", "3,333,333"] }, { "units": ["fine"], "extra": ["44"], "price": ["4,444,444"] }, { "units": ["thanks", "good"], "extra": ["55", "66"], "price": ["5,555,555", "6,666,666"] }], "residence_p": [{ "start_date": ["1111", "2222"], "end_date": ["1111", "2222"], "price_change": ["1111", "2222"] }, { "start_date": ["3333", "4444"], "end_date": ["3333", "4444"], "price_change": ["3333", "4444"] }, { "start_date": ["5555", "6666"], "end_date": ["5555", "6666"], "price_change": ["5555", "6666"] }] }] 

    更新:

    我在数据库表的一行中插入了几个带有json_encodearray )值,现在希望用jquery将它们作为顺序回显。

    输出js代码是这样的:

    1
    hello111,111,111
    how222,222,222
    what333,333,333,
    111111111111
    222222222222

    2
    fine444,444,444
    333333333333
    444444444444

    3
    thanks555,555,555
    good666,666,666
    555555555555
    666666666666

    4

    您在residence_u中只有3个元素,在residence_p数组中只有2个元素,但在原始酒店数组中只有4个元素。 是否可以像检查有效的info_ru一样简单

     var info_ru = data[0].residence_u[index]; if ( infor_ru != null ) { $.each(info_ru.units, function (index, value) { $tooltip.append(value + ' & ' + info_ru.extra[index] + ' & ' + info_ru.price[index] + '
    '); }); }

    在继续每个之前?