2016-06-01 24 views
0

在Telerik的劍道UI 2016 Q2我要創建數據源:劍道數據源 「E未定義」 錯誤

var dat1 = '{"items":[{ name: "Pork", category: "Food", subcategory: "Meat" },{ name: "Pepper", category: "Food", subcategory: "Vegetables" },{ name: "Beef", category: "Food", subcategory: "Meat" }]}'; 
var dataSource = new kendo.data.DataSource({ 
    data: dat1, 
    dataType: "json", 
    schema: { 
     data: "items" 
    } 
}); 
dataSource.fetch(function() { 
}); 

但我在Firefox/Firebug的得到這個錯誤

類型錯誤:e是未定義

我知道錯誤是爲"schema: {data:"items"}"

也將dataType更改爲jsonp並具有相同的錯誤。

+0

這是否發生在獲取創建JSON?嘗試爲數據源添加模型或嘗試使用'datasource.read()' – TheUknown

+0

爲什麼要將dat1設置爲字符串? – whipdancer

回答

0

嘗試使用:

schema: { 
data: function(response) { 
    return response.items; } 
} 

然後在調試器中觀看什麼原因造成的錯誤

而且DAT1是一個字符串,使用JSON.parse從中