2013-01-04 29 views
0

我有一個劍道下降Downlist下面的代碼結合到一個REST終點綁定劍道的DropDownList的RESTful Web服務

ddChange.kendoDropDownList({ 
    dataSource: { 
     transport: { 
      read: { 
       url: "http://localhost/Project/MyMethod", 
       dataType: "json" 
      }, 
      parameterMap: function() { 
       return { 
        source: data.source, 
        c: data.c, 
        ch: data.ch, 
       }; 
      }, 
      schema: { 
       data: function (response) { 
        return $.parseJSON(response); 
       } 
      } 
     } 
    }, 
    dataTextField: "name", 
    dataValueField: "id", 
    change: ddChange 
}); 

一切都看似工作,除了端部。致電http://localhost/Project/MyMethod?source=1&c=2&ch=3發生,我可以看到它發生並返回正確的數據,但schema > datareturn $.parseJSON(response);不是我的下拉只是包含許多未定義的條目,因爲我剩下一個字符串,仍然需要解析爲一個數組。

這樣做是否適用於Kendo Grid,它是否適用於下拉列表?我錯過了什麼嗎?

+1

爲什麼你解析響應,如果它已經在json? – NunoCarmo

+0

它不是JSON,它是一個JSON字符串,它被解析爲一個對象。我可能會誤解艱難的事情。 – Matt

+0

你能分享一個你的迴應數據的例子嗎? – NunoCarmo

回答

2

模式不是傳輸對象的一部分,而是數據源的屬性。

你可以試試嗎?

ddChange.kendoDropDownList({ 
    dataSource: { 
     transport: { 
      read: { 
       url: "http://localhost/Project/MyMethod", 
       dataType: "json" 
      }, 
      parameterMap: function() { 
       return { 
        source: data.source, 
        c: data.c, 
        ch: data.ch, 
       }; 
      } 
     }, 
     schema: { 
      data: function (response) { 
       return response; 
      } 
     } 
    }, 
    dataTextField: "name", 
    dataValueField: "id", 
    change: ddChange 
}); 

或者,如果你只在模式上做這件事,你可以忽略它。