Hi,
I've successfully managed to built an MVVM mobile application getting its data from a REST service and load a listview mobile control. However I don't seem to be able to refresh the data using the "pull to refresh" event.of the listview control.
What I'd like to know is, given the code below, how I can bind to the "pull to refresh" event from a view-model and make a call to the model entity.
Thanks for your help.
Best regards,
Gilles Kern
here is my code:
Main.js:
View-Model:
View:
Model:
I've successfully managed to built an MVVM mobile application getting its data from a REST service and load a listview mobile control. However I don't seem to be able to refresh the data using the "pull to refresh" event.of the listview control.
What I'd like to know is, given the code below, how I can bind to the "pull to refresh" event from a view-model and make a call to the model entity.
Thanks for your help.
Best regards,
Gilles Kern
here is my code:
Main.js:
01.
// Variables
02.
var
SPSite =
"https://cerfich.sharepoint.com"
;
03.
04.
// Wait for Icenium to load
05.
document.addEventListener(
"deviceready"
, onDeviceReady,
false
);
06.
07.
function
onDeviceReady() {
08.
09.
// Authenticate against SharePoint server
10.
SPOAuth(SPSite);
11.
12.
// Initialize ListView
13.
$(
"#listview"
).kendoMobileListView({
14.
pullToRefresh:
true
15.
});
16.
17.
// apply the bindings
18.
kendo.bind($(
"#ListSPItems"
), VMListSPItems);
19.
}
View-Model:
01.
var
VMListSPItems = kendo.observable({
02.
03.
// Hold SharePoint list items
04.
GetCustomers:
function
(e)
05.
{
06.
var
Customers = GetAllCustomers(SPSite);
07.
Customers.success(
function
(data){
08.
// Get Value from SharePoint
09.
var
AllCustomers =
null
;
10.
AllCustomers = data.d.results;
11.
12.
// Update data
13.
VMListSPItems.set(
"GetCustomers"
, AllCustomers);
14.
});
15.
},
16.
});
View:
01.
<
div
data-role
=
"view"
id
=
"ListSPItems"
data-title
=
"Customers List"
data-layout
=
"mobile-tabstrip"
>
02.
<
div
id
=
"CustomersError"
/>
03.
04.
<
ul
id
=
"listview"
data-bind
=
"source: GetCustomers"
data-template
=
"itemTemplate"
></
ul
>
05.
06.
<
script
id
=
"itemTemplate"
type
=
"text/x-kendo-template"
>
07.
<
li
><
a
> ${data.Title} </
a
></
li
>
08.
</
script
>
09.
</
div
>
Model:
01.
function
GetAllCustomers(siteurl)
02.
{
03.
return
$.ajax({
04.
url: siteurl +
"/_api/lists/getByTitle('Customers')/items"
,
05.
type:
"GET"
,
06.
headers: {
07.
"ACCEPT"
:
"application/json;odata=verbose"
08.
},
09.
//success: function (data)
10.
//{
11.
// //array = data.d.results;
12.
// Customers = data.d.results;
13.
//},
14.
error:
function
(xhr, ajaxOptions, thrownError){
15.
//var message = xhr.responseText.find("message").text();
16.
var
message = xhr.responseText;
17.
$(
"#CustomersError"
).html(message);
18.
}
19.
});
20.
}