Auto populate kendo box using jquery selector -


i have multiple tags below in html.

<li data-code="abc" <li data-code="xyz" <li data-code="pqr" 

i need add 3 values kendo auto complete box.

<input id='mykendobox'/> 

i used below code list.

var items = $("li").map(function () { return $(this).attr("data-code"); }).get(); 

i have 2 questions: how make sure fourth empty item doesn’t come in “items” list? how populate items in kendo auto complete box?

your li items not closed, did realize?

for populating autocomplete might do:

given input html (autocomplete):

<input id='mykendobox'/> 

and initialization follow:

var data = []; var autocomplete = $("#mykendobox").kendoautocomplete({     datasource: data }).data("kendoautocomplete"); 

when want add elements do:

var items = $("li").map(function () { return $(this).attr("data-code"); }).get(); autocomplete.datasource.data(items); 

if want limit <li> elements found jquery selector might define them as:

<ul id="autocompleteoptions">     <li data-code="abc"></li>     <li data-code="xyz"></li>     <li data-code="pqr"></li> </ul> 

and change selector to:

var items = $("li", "#autocompleteoptions").map(function () { return $(this).attr("data-code"); }).get(); 

this restricts <li> found under #autocompleteoptions.

example running in jsfiddle


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -