【问题标题】:Try loading data from JSON using JsGrid MVC尝试使用 JsGrid MVC 从 JSON 加载数据
【发布时间】:2017-03-29 17:24:29
【问题描述】:

我从 JSON 加载数据时遇到问题,当我将 JSON 分配给 JsGrid 的属性“数据”时,在表中找不到数据。我正在使用 Ajax 检索数据。

$.ajax({
            url: '@Url.Action("consulta_Unidades")',
            async: false,
            type: 'POST',
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            success: function (response) {                   
                //console.log(response.value);
                datos = JSON.stringify(response);
                alert(datos);
            }
        });

接下来是 JsGrid 代码。

$("#table_div").jsGrid({

            width: "100%",
            height: "auto",

            editing: true,

            data: datos,

            fields: [
                { name: "id_almacen", type: "text", width: 150 },
                { name: "idunidad", type: "text", width: 150 },
                { name: "tipo_unidad", type: "text", width: 150 },
                { name: "nomenclatura ", type: "text", width: 150 },
                { name: "capacidad_tarimas", type: "text", width: 150 },
                { name: "altura", type: "text", width: 150 },
                { type: "control" }

            ]
        });

有解决这个问题的办法吗?

【问题讨论】:

  • 你能分享你对alert(datos);的看法吗?
  • @Leonardo_Aguilar,在确定您尝试设置的数据格式之前,我们将无法提供帮助。所以请按照@Old_Geezer 的要求向我们提供alert(datos) 的结果。

标签: json asp.net-mvc jsgrid


【解决方案1】:

在你的 ajax 成功“响应”它是一个 json 对象,只检查

if(response){
 datos=response
}

另一种情况:

属性“数据”应该是像json这样的“对象”。

改变

datos = JSON.stringify(response);

对于

datos = JSON.parse(response);

使用

datos = JSON.parse(JSON.stringify(response));

仅当对象“响应”需要时

【讨论】:

  • 感谢 Jorge... 实际上它有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 2019-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多