2014-02-10 78 views
0
dsDetails = new kendo.data.DataSource({ 
    transport: { 
     read: { 
      url: PRODUCTDETAILAPI, 
      dataType: "json", 
      data: { "site_key": SITEKEY, "id": id } 
     } 
    } 
}); 

dsDetails.fetch(function() { 
    var myData = dsDetails.data(); 
    console.log(myData); 

    // bind stuff here 

}); 

的API調用返回以下數據(所以我知道這是工作):錯誤獲取數據

{ 
    "main_category": "Gifts", 
    "expires_on": null, 
    "html_address": "678 Sterling Drive\u003Cbr/\u003ESuite 102\u003Cbr/\u003ESanford FL 32771", 
    "address": "678 Sterling Drive Suite 102, Sanford Florida 32771", 
    "status": "Visible", 
    "rating": 5, "sub_category": "Gift Baskets", 
    "quantity": 92, "categories": ["Gifts: Gift Baskets"], "title": "Luggage Duffel", 
    "price": 12210, "images": [], "short_address": "Sanford FL", 
    "short_title": "Luggage Duffel", 
    "posted_at": "2011/09/23", 
    "category": "Gifts: Gift Baskets", 
    "id": "product_listing_88", 
    "price_note": "", 
    "description": "Black, 60 in long", 
    "seller": "Morning Star Media Group" 
} 

當我運行這段代碼,我得到了以下錯誤:

Uncaught TypeError: Object #<Object> has no method 'slice' 

編輯:基於選定的答案,我用標準的jQuery .ajax調用替換這個kendo數據集代碼,它工作正常。我的大腦暫時停留在Kendo框架的範圍內。

+0

它只是返回一個對象,或包含該對象的數組? –

+0

只有一個對象返回從這個API – zkent

回答

2

dataSource用於從服務器獲取對象的集合。從服務器返回的項目不是集合時引發此異常。相反,它是一個實際上擁有數組的字段。

如果要使用的數據集(數組)是返回對象中的某個字段,則應該使用dataSource.schema.data配置來指定該字段,以便dataSource可以瞭解從響應中的哪個字段搜索集合。

+0

好吧,這是有道理的。但你可以從上面的數據中看到*我沒有*包含在特定字段中的數據。 – zkent

+0

這是哪個領域? –

+0

我需要整個對象,而不僅僅是一個字段。也許我只需要一個vanilla .ajax調用而不是數據集? – zkent