【问题标题】:How to handle objects in typeahead?如何处理预先输入的对象?
【发布时间】:2015-10-04 07:26:50
【问题描述】:

为了简单起见,让我们以这里的第一个最简单的示例为基础:https://twitter.github.io/typeahead.js/examples/

这是本示例的建议数组:

var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
  'Colorado', 'Connecticut'  etc..
];

我想在这个数组中有对象:

var states = [
    {name: 'Alabama', image: 'images/Alabama.jpg', objectId: '123'},
    {name: 'Alaska', image: 'images/Alaska.jpg', objectId: '341'},
    {name: 'Arizona', image: 'images/Arizona.jpg' objectId: '546'},
];

当我按下“输入”键或单击其中一个建议时,我需要提取这个特定对象并将.push 提取到另一个数组中。 我该如何实现?

【问题讨论】:

    标签: javascript typeahead.js typeahead bootstrap-typeahead twitter-typeahead


    【解决方案1】:
    $(textbox-id).on('typeahead:selected', function (e, datum) {
        console.log(datum); //object
        console.log(datum.value); // will print Value you have clicked like Alabama is selected then Alabama is printed in the console.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-17
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多