문제

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