How to set the value of a Kendo AutoComplete control to a javascript object? - Stack Overflow

I have a KendoUI AutoComplete control bound to a list of objects. What I can't figure out is how t

I have a KendoUI AutoComplete control bound to a list of objects. What I can't figure out is how to set the selected value of the AutoComplete from javascript. For example:

<input id="autoplete" />
<script>
  $("#autoplete").kendoAutoComplete({
    dataTextField: "Name",
    dataSource: [ 
      { id: 1, Name: "Apples" }, 
      { id: 2, Name: "Oranges" }, 
      { id: 3, Name: "Carrots" } ]
  });

  $("#autoplete").data("kendoAutoComplete").value({ id: 2, Name: "Oranges" });
</script>

This just results in the AutoComplete control showing [object Object]. A jsBin of the problem is available here: jsBin

Any suggestions? Jason

I have a KendoUI AutoComplete control bound to a list of objects. What I can't figure out is how to set the selected value of the AutoComplete from javascript. For example:

<input id="autoplete" />
<script>
  $("#autoplete").kendoAutoComplete({
    dataTextField: "Name",
    dataSource: [ 
      { id: 1, Name: "Apples" }, 
      { id: 2, Name: "Oranges" }, 
      { id: 3, Name: "Carrots" } ]
  });

  $("#autoplete").data("kendoAutoComplete").value({ id: 2, Name: "Oranges" });
</script>

This just results in the AutoComplete control showing [object Object]. A jsBin of the problem is available here: jsBin

Any suggestions? Jason

Share Improve this question asked May 27, 2014 at 17:10 JasonJason 2,6174 gold badges43 silver badges48 bronze badges 2
  • Use $("#autoplete").data("kendoAutoComplete").value("Oranges"); – OnaBai Commented May 27, 2014 at 18:25
  • Arg, I thought I'd tried that. Must have had something else wrong at the time. Thanks OnaBai! Add your ment as an answer and I'll set it as the Answer. – Jason Commented May 27, 2014 at 18:38
Add a ment  | 

1 Answer 1

Reset to default 3

Answer from OnaBai

$("#autoplete").data("kendoAutoComplete").value("Oranges");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745327768a4622737.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信