Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Asp.net MVC Ajax迭代_Jquery_Asp.net_Ajax_Json - Fatal编程技术网

Jquery Asp.net MVC Ajax迭代

Jquery Asp.net MVC Ajax迭代,jquery,asp.net,ajax,json,Jquery,Asp.net,Ajax,Json,我使用$.getJSON将一个对象返回到我的视图。该对象包含许多列表,我需要对这些列表进行迭代。如何做到这一点?到目前为止,我的代码是: $.getJSON("/Home/GetData", function (data) { $.each(data, function (index) { //access data here for each list in object? });

我使用$.getJSON将一个对象返回到我的视图。该对象包含许多列表,我需要对这些列表进行迭代。如何做到这一点?到目前为止,我的代码是:

$.getJSON("/Home/GetData",
        function (data) {
            $.each(data, function (index) {
                //access data here for each list in object?
            });
        });

谢谢。

使用$时,签名为:

$.each(data, function (index, item) {
    //access data here for each list in object?
});
因此,可以直接访问该项目。此外,我认为应该将列表作为数组向上推,这样您就可以根据需要拥有任意数量的$。每条语句。下一个内部阵列将通过以下方式提供:

$.each(item.SubList, function(si, sitem) {

});
如果你发布推送的数据结构,我们可以提供更多帮助。另外,您返回的对象是匿名类还是强类型?您是否返回JsonResult


HTH.

使用$。每个时,签名为:

$.each(data, function (index, item) {
    //access data here for each list in object?
});
因此,可以直接访问该项目。此外,我认为应该将列表作为数组向上推,这样您就可以根据需要拥有任意数量的$。每条语句。下一个内部阵列将通过以下方式提供:

$.each(item.SubList, function(si, sitem) {

});
如果你发布推送的数据结构,我们可以提供更多帮助。另外,您返回的对象是匿名类还是强类型?您是否返回JsonResult


HTH.

如果我理解您在这里的要求,您将得到以下形式的JSON对象:

// result
{
    people: [{...}, {...}, ... , {...}],
    places: [{...}, {...}, ... , {...}],
    ...
}
您应该首先迭代返回的JSON对象,然后逐个迭代每个列表的项。大致如下:

$.getJSON("/Home/GetData", function (data) {
    // iterate over lists in an object
    for(var list in data)
    {
        // list variable holds the name of the list (ie. "people")
        // iterate over list items
        $.each(data[list], function (index) {
            // do something with this list item
        });
    }
});

如果我理解您在这里的要求,您将得到以下形式的JSON对象:

// result
{
    people: [{...}, {...}, ... , {...}],
    places: [{...}, {...}, ... , {...}],
    ...
}
您应该首先迭代返回的JSON对象,然后逐个迭代每个列表的项。大致如下:

$.getJSON("/Home/GetData", function (data) {
    // iterate over lists in an object
    for(var list in data)
    {
        // list variable holds the name of the list (ie. "people")
        // iterate over list items
        $.each(data[list], function (index) {
            // do something with this list item
        });
    }
});

无需通过项目访问当前项目。您可以轻松地使用此项。无需通过项访问当前项。你可以很容易地使用这个。这个代码看起来很好。。。你想完成什么?您需要遍历所有列表的项还是遍历列表…这段代码似乎很好。。。你想完成什么?您需要遍历所有列表的项还是遍历列表。。。