I have the following code and I am trying to get the count of returned records without having to issue a second fetch() command:

dsOffers = new kendo.data.DataSource({
    transport: {
        read: {
            url: PRODUCTAPI,
            data: getOfferData()
        }
    },
    serverPaging: true,
    pageSize: 50,
    schema: {
        data: "results",
        total: "count",
        model: { id: "id" }
    }
})
.bind("error", namespace.dataSource_error);

dsOffers.total(); // returns 0

// if I use this, my API is hit twice
dsOffers.fetch(function() {
    console.log(dsOffers.total()); // returns 3
});
有帮助吗?

解决方案

The problem is that it takes time loading the data (it happens asynchronously -in background/parallel-). If you print it just after the initialization you actually don't have the data available.

This is the correct behaviour.

If you don't want to do the second fetch you should print it in the dataBound event.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top