Domanda

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

});

The API call is returning the following data (so I know that is working):

{
    "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"
}

When I run this code I get the following error:

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

Edit: Based on the selected answer, I replace this kendo dataset code with a standard jQuery .ajax call and it worked fine. My brain was temporarily stuck within the confines of the Kendo framework.

È stato utile?

Soluzione

The dataSource is used to get collection of objects from the server. This exception is thrown when the item returned from the server is not the collection. Instead it is an object which has a field that actually holds the array.

If the dataset (array) that you want to use is one of the fields in the returned object, you should use dataSource.schema.data configuration to specify that field, so the dataSource can understand in which field from the response to search the collection.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top