0

我的 php 文件创建了一个 jsonp 响应,它有 4 个单独的对象,它们有自己的嵌套。我想知道如何只通过一个嵌套来执行 $.each() ,而不是一次检索所有值,因为我对待每个值都不同。例如,我只想使用 [SubmittedAddress] 下的 $.each 函数浏览所有数据。我通过 jquery ajax 函数调用它。为了便于阅读,这里是非 jsonp 格式的数组:

Array
(
    [SubmittedAddress] => Array
        (
            [address1] => 850 BRYANT STREET
            [address2] => 
            [addresscombined] => 850 BRYANT STREET
            [city] => SAN FRANCISCO
            [state] => CA
            [zip] => 94106
        )

    [CorrectAddress] => Array
        (
            [address1] => SUPERIOR COURT
            [addresscombined] => SUPERIOR COURT 850 BRYANT ST STE 306
            [address2] => 850 BRYANT ST STE 306
            [city] => SAN FRANCISCO
            [state] => CA
            [zip] => 94103
            [zip4] => 4667
        )

    [PercentMatch] => Array
        (
            [addresscombined] => 39
            [city] => 100
            [state] => 100
            [zip] => 80
        )

    [Response] => success
)

这是我的 jsonp 得到的,它遍历每一个值,而不仅仅是 [SubmittedAddress] 中的值

success: function(data, textStatus){
    $.each(data, function(index, object) {
        $.each(object, function(property, value) {
            alert(property + "=" + value);
        }); 
    });
},

先感谢您。

4

1 回答 1

2

If you want to process one property then do precisely that, e.g.

success: function(data, textStatus){
    $.each(data.SubmittedAddress, function(index, object) {
        alert(property + "=" + value);
    });
    $.each(data.CorrectAddress, function(index, object) {
        console.log(property + "=" + value);
    });
    //etc
},
于 2013-01-07T01:32:24.480 回答