Javascript 如何使用嵌套模型填充剑道UI网格?
我正在尝试将我的剑道UI网格绑定到具有嵌套模型类别的嵌套模型类产品。我已经按照文档给出了一切,但我无法找出我的代码有什么问题Javascript 如何使用嵌套模型填充剑道UI网格?,javascript,asp.net-mvc,kendo-ui,nested,Javascript,Asp.net Mvc,Kendo Ui,Nested,我正在尝试将我的剑道UI网格绑定到具有嵌套模型类别的嵌套模型类产品。我已经按照文档给出了一切,但我无法找出我的代码有什么问题 schema: { data: "data", total: "Total", model: { // define the model of the data source. Required for validation and property types.
schema: {
data: "data",
total: "Total",
model: { // define the model of the data source. Required for validation and property types.
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitPrice: { type: "number", validation: { required: true, min: 1 } },
Discontinued: { type: "boolean" },
UnitsInStock: { type: "number", validation: { min: 0, required: true } },
CategoryName: { from: "Category.CategoryName", validate: { required: true } }
}
}
},
并在网格的列中使用此模型
columns: [
"ProductName",
{ field: "UnitPrice", format: "{0:c}", width: "150px" },
{ field: "UnitsInStock", width: "150px" },
{ field: "Discontinued", width: "100px" },
{ field: "QuantityPerUnit", width: "100px" },
{ field: "CategoryName", title: "Category", width: "100px" },
{ command: "destroy", title: "Delete", width: "110px" },
以下是从服务器返回的我的模型
var resl = productService.GetProducts(take, skip, ref Total);
var data = resl.ToList();
// Return as JSON - the Kendo Grid will use the response
return Json(new { Total = Total, data = data });
现在,所有列都成功地与类别名称列的grid execept绑定。我是否遗漏了什么或做错了什么
已更新-以下是我的服务器产品视图模型
public class ProductViewModel
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public string QuantityPerUnit { get; set; }
public Int32 UnitsInStock { get; set; }
public int? UnitsOnOrder { get; set; }
public int? ReorderLevel { get; set; }
public bool Discontinued { get; set; }
public int? SupplierID { get; set; }
public int? CategoryID { get; set; }
public CategoryViewModel Category { get; set; }
这就是我在客户端接收数据的方式
我现在无法尝试,但有一个想法:您的控制器响应在顶层包含一个名为CategoryName的字段,并且在您的模型中定义了另一个同名字段。。。即使您告诉它您希望将其映射到Category.CategoryName,我认为它可能从您的响应中获取顶级CategoryName(未定义) 尝试在模型中为CategoryName使用其他名称。。。。与响应中的任何名称都不匹配的名称,然后查看是否匹配
发回结果。祝你好运在度过了漫长的两天之后,我终于解决了这个问题。问题是,我根据文档在Knedo网格中显式地定义了列CategoryName,这不是必需的,我只是删除了它,并在schema model字段中添加了以下行
{ field: "Category.CategoryName", width: "100px" },
通过这种方式,嵌套模型的属性直接绑定到列。我必须说剑道的文件很糟糕 您可以发布一个简短的数据示例吗?当然,我会更新我的问题。实际上,您正在查看的顶级字段CategoryName是我在kendo网格的模式模型中创建的,以下是嵌套模型的文档。您可以发布文档文章的链接吗?我是不是遗漏了什么?