2

我希望预先输入的建议菜单根据所选菜单显示不同的结果,如下结构:

var colors = ["red", "blue", "green", "yellow", "brown", "black"];
var numbers = ["One", "Two", "Three", "Four", "Five", "Six"];
var names = ["Ahmad", "Ali", "Hatem", "Wesam", "Nour", "Jeorge"];

$( "#search1" ).attr("autocomplete", "off");
$( "#search-fld" ).typeahead({source: colors});

$("#search-drop li a").click(function(){
    $("#search-btn").text($(this).text()); 
    if($(this).text() == 'People') {
        $( "#search-fld" ).typeahead({source: names});
    } else if($(this).text() == 'Salaries') { 
        $( "#search-fld" ).typeahead({source: numbers});
    } else if($(this).text() == 'Jobs') { 
        $( "#search-fld" ).typeahead({source: colors});
    }
});

这是jsfiddle的示例。但问题是即使我选择不同的子菜单,相同的结果也会不断出现。

我想知道如何从不同的资源加载不同的 typeahead 结果。

请指教,

================================

动态预输入错误

================================

新错误

4

1 回答 1

2

这应该有效:

$("#search-drop li a").click(function(){
        $("#search-btn").text($(this).text()); 
        if($(this).text() == 'People') {
            $( "#search-fld" ).data('typeahead').source = names;
        } else if($(this).text() == 'Salaries') { 
            $( "#search-fld" ).data('typeahead').source = numbers;
        } else if($(this).text() == 'Jobs') { 
            $( "#search-fld" ).data('typeahead').source = colors;
        }
});
于 2013-04-03T22:05:09.683 回答