javascript
  • post
  • kendo-ui
  • 2015-06-30 121 views 0 likes 
    0

    这里是我的网格:剑道格删除按钮不会触发删除功能

    $("#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, 
    }); 
    

    莫名其妙的读取功能工作正常,但是当我按下删除按钮我甚至不会达到我的参数映射功能。 当我在铬控制台看,没有请求发送到我的控制器。

    这里是我的控制器方法:

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

    也许尝试移除类型:“JSON”(根据文档的HTTP ://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-type,这不是dataSource.type的有效设置) –

    +0

    谢谢!但这并没有帮助:( –

    +0

    哦,我认为你需要在参数映射函数中返回某些操作被销毁时的东西 –

    回答

    0

    让我试着回答,但要注意,我改变你的运输和列设置使用剑道领域的匹配,因为很显然,我不能用你。与此相似

    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”上读取和删除通话,其实你并不需要它们?

    但后来你说你不能达到parameterMap的,我来到 想起

    • 您可以设置editable : false,你怎么可以修改它,如果你 将其设置为假?你应该把它做出editable : true(注意:你也可以尝试将其设置为false,那么你就可以看到删除功能将无法正常工作)

    DEMO

    0

    而不是stringifing {param:value}简单字符串化值即stringify(options.models)为参数category

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

    也许你应该编辑你的答案以包含一个描述如何回答这个问题。 –

    相关问题