【问题标题】:Having trouble to typeaheadjs无法提前输入
【发布时间】:2013-04-25 10:03:42
【问题描述】:

我使用了以下脚本:

<input class="typeahead" type="text" id = "input">
$('#input').typeahead([{name: 'name',remote: 'planets.json',}]);

JSON 文件

{"name" : {"value" : ["4729", "Siva", "Prakash"]},"planets" : {"value" : ["Mercury", "Venus", "Pluto"]}}

在输入框输入时,显示两个Json数组名value[name,plants]。无论如何,在我的代码中,我只提到名称作为“名称”。所以它必须只从'name' JSON 数组中返回该值?

【问题讨论】:

    标签: typeahead typeahead.js


    【解决方案1】:

    planets.json 中,它是名称-> 值,或行星-> 值。像这样初始化预输入:

    <input type="text" id="input" data-provide="typeahead">
    
    $.getJSON("planets.json", function(json) {
       $('#input').typeahead({ 
         source : json.name.value
       });
    });
    

    json.planets.value,如果你想要行星

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-14
      • 1970-01-01
      • 2016-10-07
      • 2019-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多