在类型前面的js中获取搜索数据的数组名称

时间:2015-09-24 09:27:42

标签: javascript typeahead

$('#search_restaurant').typeahead({
minLength: 1,
order: "asc",
 template: "{{display}} <small style='color:#999;' id={{group}}>{{group}} </small>",
source: {
Restaurant: {
    url: ["sqlfiles/search_data.php", "data.country"]
},
Estb: {
    url: ["sqlfiles/search_data.php", "data.dish"]
},
Sub: {
    url: ["sqlfiles/search_data.php", "data.sub"]
},
Cusines: {
    url: [
        {
            type: "POST",
            url: "sqlfiles/search_data.php",
            data: {myKey: "myValue"}
        },
        "data.capital"
    ]
}
},

});

我正在使用运行编码器类型提前js在这里我得到的数据但我想要的是所选数据的数组的名称,如java脚本变量中的Restaurant,Estb,Sub,Cusines

1 个答案:

答案 0 :(得分:0)

callback: {
    onClickAfter: function (node, a, item, event) {
        // item.group should be what you are looking for
        console.log(item)
    }
}
});

解决方案