<
ul
id
=
"books"
></
ul
>
<
script
id
=
"template"
type
=
"text/x-kendo-template"
>
<
li
class
=
"book"
>
<
a
href
=
"#= url #"
>
<
h3
>#= title #</
h3
>
</
a
>
by #= author #
</
li
>
</
script
>
<
script
>
$(document).ready(function () {
function onChage() {
$("#books").html(kendo.render(template, this.view()));
}
// create a template using the above definition
var template = kendo.template($("#template").html());
var dataSource = new kendo.data.DataSource({
transport: {
// specify the XML file to read. The same as read: { url: "books.xml" }
},
schema: {
// specify the the schema is XML
type: "xml",
// the XML element which represents a single data record
data: "/books/book",
// define the model - the object which will represent a single data record
model: {
// configure the fields of the object
fields: {
// the "title" field is mapped to the text of the "title" XML element
title: "title/text()",
// the "author" field is mapped to the text of the "author" XML element
author: "author/text()",
// the "url" field is mapped to the text of the "url" XML element
url: "url/text()",
// the "cover" field is mapped to the "id" attribute of the "book" XML element
cover: "@cover"
}
}
},
change: onChage
});
dataSource.read();
});
</
script
>
What is the proper way to edit items in a listview when using Kendo UI Mobile & MVVM?
I don't get the expected results when using the following:
HTML
<div id="itemsView"
data-role="view"
data-model="vm">
<ul data-role="listview" data-bind="source: items"
data-template="itemsTemplate">
</ul>
<script id="itemsTemplate" type="text/x-kendo-template">
<li>
#=Name#
</li>
</script>
<input type="text" data-bind="value: newValue" />
<button data-role="button" data-bind="click: update">update</button>
</div>​
JavaScript
var vm = kendo.observable({
items: [{
Name: "Item1"}],
newValue: '',
update: function(e) {
var item = this.get("items")[0];
item.set("Name", this.get("newValue"));
//adding the follwoing line makes it work as expected
kendo.bind($('#itemsView'), vm);
}
});
kendoApp = new kendo.mobile.Application(document.body, {
transition: "slide"});​
I expect the listview to reflect the change to the Name property of that item. Instead, a new item is added to the listview. Examining the array reveals that there is no additional item, and that the change was made. (re)Binding the view to the view-model updates the list to reflect the change. Re-Binding after a change like this doesn't seem to make any sense.
Here is the jsfiddle: http://jsfiddle.net/5aCYp/2/
Note: This was originally posted on StackOverflow:
http://stackoverflow.com/questions/13739125
$("#homesGrid").data("kendoGrid").dataSource.page();
In databound event of Kendo Grid, I cannot set his selected page. I can only set his selected row by
$("#homesGrid").data("kendoGrid").dataSource.page(2); ====> error
var data = mygrid.dataSource.data();
$.each(data, function (i, row) {
if (row.Fcode == fcode) {
$('tr[data-uid="' + row.uid + '"]').addClass("k-state-selected");
}
Is the code of that line incorrect or is that I cannot set it in databound event of Kendo Grid?