剑道网格删除按钮没有't触发删除功能

kendo grid delete button doesn't trigger delete function

本文关键字:删除 功能 网格 按钮      更新时间:2023-09-26

这是我的网格:

$("#category-gridview").kendoGrid({
     dataSource: {
         type: "json",
         transport: {
             read: {
                 url: function (options) {
                     return '/Product/GetCategories?id=' + $("#selectedProductId").val() + '&company=' + $("#company-dropdown").val() + '&language=' + $("#country-dropdown").val();
                 },
                 dataType: "json",
                 type: "POST"
             },
             destroy: {
                 url: '/Product/DeleteProductCategory',
                 dataType: "json",
                 type: "POST",
                 contentType: "application/json"
             },
             parameterMap: function (options, operation) {
                 console.log("HÄÄR");
                 console.log(options);
                 if (operation !== "read" && options.models) {
                     return JSON.stringify({
                         category: options
                     });
                 }
             }
         },
         schema: {
             model: {
                 fields: {
                     id: {
                         type: "string"
                     },
                     name: {
                         type: "string"
                     },
                 }
             }
         },
     },
     columns: [{
         field: "id",
         hidden: true
     }, {
         field: "name",
         title: "Category",
         width: "30px"
     }, {
         command: "destroy",
         title: " ",
         width: 15
     }],
     editable: false,
 });

不知何故,读取功能如预期一样工作,但当我按下删除按钮时,我甚至无法到达参数映射功能。当我在chrome控制台中查看时,没有向我的控制器发送请求。

这是我的控制器方法:

[HttpPost]
public JsonResult DeleteProductCategory(CategoryResponse category)
{
    return Json(category);
}

让我试着回答,但要注意的是,我使用剑道更改了您的传输和列设置以匹配字段,因为显然我不能使用您的。类似于此

transport: {
             read: {
                 url: "http://demos.telerik.com/kendo-ui/service/products",
                 dataType: "jsonp"
             },
             destroy: {
                 url: "http://demos.telerik.com/kendo-ui/service/products/destroy",
                    dataType: "jsonp"
             },
             parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                        return {models: kendo.stringify(options.models)};
                    }
                }
}, 
  • 乍一看,我注意到您在读取和删除调用时使用了"POST",实际上您不需要它们吗

但后来你说你无法访问参数映射,我来了想想

  • 您设置了editable : false,如果您设置为false?您应该将其设置为editable : true(注意:您也可以尝试将其设置成false,然后您可以看到删除功能将不起作用)

演示

不字符串化{param:value},只字符串化值,即参数categorystringify(options.models)

parameterMap: function(options, operation) {
                                if (operation !== "read" && options.models) {
                                    return { category: kendo.stringify(options.models) };
                                }
                            }