Frage

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
});
War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top