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?
ViewBag.Title = "Index";}@section Scripts { <script type="text/javascript"> var viewModel; $(function () { // Load Data $.ajax({ async: false, url: "/Kendo/Home/GetData" }).success(function (result) { viewModel = new kendo.observable(result); }); // Create Grid $("#grid").kendoGrid({ dataSource: { data: viewModel.People, schema: { model: { fields: { DOB: { type: "date" } } } } }, columns: [ { field: "FirstName", title: "First Name" }, { field: "LastName", title: "Last Name" }, { field: "DOB", title: "Date of Birth", format: "{0:MM/dd/yyyy}" } ], editable: true }); $(document).on("click", "#btn-save", function (e) { $.ajax({ url: "/Kendo/Home/Save", type: "POST", data: JSON.stringify(viewModel), contentType: "application/json" }).success(function (result) { var g = $("#grid").data("kendoGrid"); viewModel = new kendo.observable(result); g.dataSource.data(viewModel.People); }); }); }); </script>}<div id="grid"></div><div id="view"> <input data-bind="value: firstName" /> <input data-bind="value: lastName" /> <button id="btn-save">Save</button></div>