问题
Trying to use autocomplete but my dataTextField is an integer. So I keep getting "tolower" or "indexof" error. Cant find a single example of someone trying to autocomplete with numbers.
PS: works fine with a text field
http://jsfiddle.net/NSLp8/
$("#autocomplete").kendoAutoComplete({
dataTextField: "value",
select: function(e) {
var dataItem = this.dataItem(e.item.index());
//output selected dataItem
$("#result").html(kendo.dataItem);
},
dataSource: {
data: [
{ id : 1, value: 1 },
{ id : 2, value: 2 },
{ id : 3, value: 3 },
{ id : 4, value: 4 }
]
}
});
回答1:
As a workaround, you can try adding the toLowerCase()
prototype to Number
$(document).ready(function() {
if (!Number.prototype.toLowerCase) {
Number.prototype.toLowerCase = function() {
return this.toString();
}
}
});
$(document).ready(function() {
if (!Number.prototype.toLowerCase) {
Number.prototype.toLowerCase = function() {
return this.toString();
}
}
});
$("#autocomplete").kendoAutoComplete({
dataTextField: "value",
select: function(e) {
var dataItem = this.dataItem(e.item.index());
//output selected dataItem
$("#result").html(kendo.dataItem);
},
dataSource: {
data: [{
id: 1,
value: 1
}, {
id: 2,
value: 2
}, {
id: 3,
value: 3
}, {
id: 4,
value: 4
}]
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css" rel="stylesheet" />
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<input id="autocomplete" />
<div id="result"></div>
来源:https://stackoverflow.com/questions/15890859/kendo-autocomplete-on-numeric-field