【发布时间】:2015-10-07 05:42:57
【问题描述】:
我有两个对象从控制器传递到使用return Json(new {success = true , product, list}); 查看我只需要遍历“产品”对象。在 jQuery 中是否可行?我试过了
$.each(response, function (index, el) {
});
然后它也遍历'list'。以下是控制器在ajax成功时的响应。
[Object, Object]------->values of product
0: Object
CategoryID: 0
Description: null
PhysicalPath: null
ProductCategory: null
ProductID: 41
Title: "Woo Album"
Tooltip: null
VirtualPath: "~/Content/images/pro-cat-6.jpg"
1: Object
CategoryID: 0
Description: null
PhysicalPath: null
ProductCategory: null
ProductID: 42
Title: "EverShine Memories"
Tooltip: null
VirtualPath: "~/Content/images/pro1.jpg"
[7, 8] ---->values of list
【问题讨论】:
-
您需要提供
product和list的外观吗?此外,您获得了索引,因此您可以到达所需的元素,但您仍然需要向我们展示一些数据 -
你能发布你的
response对象的样子吗? -
[Object, Object] 0:ObjectCategoryID:0Description:nullPhysicalPath:nullProductCategory:nullProductID:41Title:“Woo Album”工具提示:nullVirtualPath:“~/Content/images/pro-cat-6.jpg” proto:Object1:ObjectCategoryID:0Description:nullPhysicalPath:nullProductCategory:nullProductID:42Title:“EverShine Memories”工具提示:nullVirtualPath:“~/Content/images/pro1.jpg”proto : Objectlength: 2__proto__: Array[0] ProductDisplay:286 [7, 8]
-
@neethu 编辑你的问题
-
根据经验,我总是将我的 Json 对象命名为,因此请将您的 Json 更改为
return Json(new { success = true, product = product, list = list });,然后使用 Thiago 的答案
标签: jquery asp.net-mvc model-view-controller