var t94StragglerCarriers = new kendo.data.DataSource({
transport: {
read: {
url: "/MenuTrain/T94StragglerCarriers",
dataType: "json"
},
schema: {
model: {
id: "id",
fields: {
id: {type : "string"} ,
val: {type : "string"}
}
}
},
pageSize: 5,
serverPaging : true
}
});
I've tried several variations for the datasource. From not specifying the schema to just specifying the id.
function onChange() {
var listView = $("#carrierList").data("kendoListView");
var index = listView.select().index();
var item = listView.dataSource.view()[index];
console.log("Item " + index + " selected. Text = " + item.id);
}
Here is the json string returned from my controller's action method:
[{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"CHTT"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"CMO "},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"CTCX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"DBUX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"GATX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"MWCX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"NDYX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"PLMX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TAEX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TCIX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TEIX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"TILX"},{"id":"10eac72a-d62d-434f-8505-4869cdb27b04","val":"UP "},{"id":"ffbcdb6c-4d3a-45f6-8ef6-ada5f28ba44b","val":"MDXx"}]
The listview renders correctly. But it's as if the listview's select().index() methods are treating each field as an item. For example , the first object's id field is index 0, the first object's val field is index 1, and so on.
What am i doing wrong here?
var carriers = $("#carrierList").kendoListView({ selectable: true, pageable : true , change: onChange, dataBound : onDataBound , dataSource: t94StragglerCarriers, template : kendo.template($("#carrierTemplate").html()) }).data("kendoListView");function onChange() { var listView = $("#carrierList").data("kendoListView"); var index = listView.select().index(); var item = listView.dataSource.view()[index]; console.log("Item " + index + " selected. Text = " + item.val); }var Model = kendo.data.Model.define({ Id: "Id", fields: { Id: { type: "string", }, Name: { type: "string", }, Mutations: [], Tags: [] }, mapping: { Tags: { children: function (data) { return $.extend(data, { onRemove: function (e) { // execute code } }); } }, Mutations: { children: function (data) { return $.extend(data, { Label: null, onRemove: function (e) { // execute code }, onEdit: function (e) { // execute code }, onSave: function (e) { // execute code } }); } } }});kendo.data.ObservableObject.prototype.fromJSON = function (source, mapping) { var name, value, observable = this; // if there is mapping given, then pass it through that first if (mapping) { source = kendo.mapping(source, mapping); } for (name in source) { if (observable.hasOwnProperty(name)) { observable.set(name, source[name]); } }}kendo.mapping = function (source, mapping) { var name, value; // if the user provides us a mapping, we can use that to help // build the objects appropriately for (name in source) { if (source.hasOwnProperty(name)) { // get the value for this property or item value = source[name]; // try to determine if this is an array, or just a // normal object. That will greatly dictate our choice of behavior if (value instanceof Array) { // if this is an array, then we will try to check for a // key in the mapping schema if (mapping[name].children) { // if we discover a mapping key for this array, we // will use it to reconstruct the array data for (var i = 0; i < value.length; i++) { source[name][i] = mapping[name].children(value[i]); } } } else { // attempt to match any non array type keys if (mapping[name]) { source[name] = mapping[name](value); } } } } return source;}// -------------------------------------------------------------// create a kendo ui grid to show the existing prototypes// -------------------------------------------------------------widgets.grid = $('#grid').kendoGrid({ dataSource: { transport: { read: { url: "/administrator/data/prototypes", dataType: "json", type: 'GET' } }, schema: { total: "total", data: "data" }, page: 0, pageSize: 15, take: 15, serverPaging: true, serverFiltering: true, type: "aspnetmvc-ajax" }, pageable: { refresh: true, pageSizes: true }, selectable: "row", columns: [ { field: "Id", width: 25, title: "Identity" }, { field: "Name", width: 40, title: "Name" } ], change: function (e) { // get the selected row from the grid var selected = this.select(); // get the data from the selected row var data = this.dataItem(selected); // update the model viewModel.fromJSON(data.toJSON(), viewModel.mapping); },}).data("kendoGrid");viewModel.Mutations.bind("change", function (e) { // do something else});-- This represents my entity and view model, both the fields are the same but have slightly different names
public class Car { public string Name { get; set; }}public class CarViewModel { public string CarName { get; set; }}var theTree = $("#treeview").kendoTreeView({ dataSource: folderArray, template: $("#foldersTemplate").html(), expand: function(e) { code for grabbing any sub-folders. }, select : function(e) { var treeviewInner = e.sender, idFolder = treeviewInner.dataItem(e.node).id; /* set-up angularjs controller scope */ window.location.href = "#/folder/" + idFolder; //navigates to the proper folder gridview when node seleced. }});