Webix - Rest Mode Support - Datatable - 为CRUD操作设置ID列

Webix - Rest Mode Support - Datatable - Set ID column for CRUD operation

我正在关注 these instructions, and adapted this example。 问题是我的数据 ID 没有命名为 ID。 因此,当我尝试更改数据时,发送到我的 REST API 的 ID 是一些疯狂的数字。

有没有办法配置我的 JSON 中的哪个数据表列或字段将用作 ID?

我是否需要更改从我的 REST 返回的名称 API 以及如何在不更改数据库结构的情况下执行此操作的最佳方法?

JSON 输出:

[
    {
        "nu_unidade": "sample string 2", 
        "nome": "sample string 4", 
    },{
        "nu_unidade": "sample string 2", 
        "nome": "sample string 4", 
    },{
        "nu_unidade": "sample string 2", 
        "nome": "sample string 4",
    }
] 

ASP 网络型号:

namespace Site.Models {
    using System;
    using System.Collections.Generic;
    public partial class Unidade {
        public string nu_unidade { get; set; }
        public string nome { get; set; }
    }
}

使用:

我很确定 Webix 不能在没有 "id" 字段的情况下工作(它会自动创建一个带有随机大整数的字段)。如果您的 API 无法发送,也许您可​​以尝试在 webix 数据表中映射数据:http://docs.webix.com/datatable__data_mapping.html

columns:[
    { 
        id:"id",  
        map:"#nu_unidade#", 
        header:"Id" 
    }
],

或者您可以在数据初始化时强制使用 id :

scheme: {
   $init:function(obj){
       obj.id = obj.nu_unidade;
     } 
}