【问题标题】:How to iterate through one of the objects of jquery success?如何遍历jquery成功的对象之一?
【发布时间】: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

【问题讨论】:

  • 您需要提供productlist 的外观吗?此外,您获得了索引,因此您可以到达所需的元素,但您仍然需要向我们展示一些数据
  • 你能发布你的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


【解决方案1】:

而是通过return Json(new {success = true , product, list});return Json(new {success = true , product, start=startIndex,end = endindex}); 传递列表,并在 jquery 中使用变量作为 response.start 和 response.end

【讨论】:

    【解决方案2】:

    你想要的对象不是响应的孩子吗?你不应该改用response.product吗?

    $.each(response.product, function (index, el) {        
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-23
      • 2014-11-30
      • 2015-11-24
      • 2011-04-10
      • 1970-01-01
      • 2015-08-24
      相关资源
      最近更新 更多