kendo autocomplete on numeric field

可紊 提交于 2019-12-24 05:56:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!