javascript
  • post
  • kendo-ui
  • 2015-06-30 114 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

    也許你應該編輯你的答案以包含一個描述如何回答這個問題。 –

    相關問題