I've set up a project following the KendoUI Mobile Music Store example and am having trouble binding my data to the model.
I've used the source code that is available on Github and can't seem to figure out how the DataSource is being populated without ever doing a DataSource.read();
The example I give below is my take on the example, but you could check out the artists-view.js to see the same.
Okay, the view javascript:
The relevant bits of the data class:
Now, this all works (sort-of) fine, but the datasource is never populated, and I feel like that is because the read() is never called. How is this working in the example?
I've used the source code that is available on Github and can't seem to figure out how the DataSource is being populated without ever doing a DataSource.read();
The example I give below is my take on the example, but you could check out the artists-view.js to see the same.
Okay, the view javascript:
define([
"kendo"
,
"app/data"
],
function
(kendo, data) {
return
{
viewModel: kendo.observable({
myData: data.myData
})
}
});
define([
"jQuery"
,
"kendo"
,
"app/environment"
,
"app/utils"
],
function
($, kendo, config, utils) {
var
DataSourceConfig =
function
(url, sortField, options) {
this
.transport = {
read:
{
url: url,
dataType:
'jsonp'
,
}
}
this
.sort = {
field: sortField,
dir:
"asc"
};
$.extend(
this
, options || {});
};
DataSourceConfig.prototype = {
type:
"GET"
,
requestStart:
function
() {
if
(
this
.pageSize() === undefined ||
this
.page() === 1) { utils.showLoading(); } },
//infinite scrolling has its own, less obtrusive indicator
requestEnd:
function
() { utils.hideLoading(); },
error:
function
() { utils.hideLoading(); utils.showError(
"There was an error loading the data from the server. Please close the app and try again."
); }
};
return
{
clear:
function
(dataSource) {
dataSource.view().splice(0, dataSource.view().length);
},
myData:
new
kendo.data.DataSource(
new
DataSourceConfig(config.myDataUrl)),
};
});