Jack Thor Jack Thor - 2 months ago 14
Javascript Question

New Kendo Data Source is null?

So I have an Array which is defined like this

var newArrary = Array();
for (var i = 0; i < result.length; i++) {
if (result[i].Id != TaskId) {
newArrary.push({text:result[i].Name, value:result[i].Id})
}
}


I did a console.log and can see that the array got initialize correctly.
enter image description here

I then went on to create a new data Source

var dataSource = new kendo.data.DataSource({
data: newArrary
});


and also check and see that it is initialize correctly

enter image description here

but when I try to set it to a dropdownlist with the
setDataSource
method on my drop down list it complains about
Uncaught TypeError: Text.indexOf is not a function


So I did a simple
dataSource.at(1)
and get 'undefined'. Not sure what I am doing wrong here?

UPDATE Adding more code:

How I Created/Configured the drop down

@(Html.Kendo().DropDownListFor(m => m)
.BindTo(list)
.DataTextField("Text")
.DataValueField("Value")
.HtmlAttributes(attributes)
.OptionLabel(string.IsNullOrEmpty(label) ? (required && @dropDownList.Value != "0" && @dropDownList.Value != "" ? "" : " ") : label)
.Value(@dropDownList.Value)
.TemplateId("myTemplate")
.ValueTemplateId("dmyTemplate")
)


And how I am using the the setDatasource

setTask = function (result, taskCodeStartList, taskCodeResultLisr) {
var selectedTaskItem = $("#" + taskStartList).data("kendoDropDownList")
var selectedFilterTask = $("#" + taskResultLisr).data("kendoDropDownList").value()
var newArrary = Array();

for (var i = 0; i < result.length; i++) {
if (result[i].Id != selectedFilterTaskId) {
newArrary.push({text:result[i].Name, value:result[i].Id})
}
}

var dataSource = new kendo.data.DataSource({
data: newArrary
});

selectedTaskCodeItem.setDataSource(dataSource);
return selectedTaskCodeItem;
};

Answer

The dataTextField and dataValueField settings are with capital letters ("Text", "Value"), but the newArrary items have fields with lowercase letters (text, value). These should match, otherwise the widget will not be able to handle the new data.

http://dojo.telerik.com/OQOle

I am not sure about the

So I did a simple dataSource.at(1) and get 'undefined'.

part, as everything else looks OK.