Javascript 引导typeahead更新程序选项
我试图使用Twitter引导的typeahead javascript的updater选项为同一行检索多个值,然后在输入框的同一选定行上显示一列,在另一行上显示另一列。不幸的是,我似乎无法找出下面的代码如何无法更新id为Javascript 引导typeahead更新程序选项,javascript,twitter-bootstrap,Javascript,Twitter Bootstrap,我试图使用Twitter引导的typeahead javascript的updater选项为同一行检索多个值,然后在输入框的同一选定行上显示一列,在另一行上显示另一列。不幸的是,我似乎无法找出下面的代码如何无法更新id为ProductName的输入框 $('#ProductName').typeahead({ source: function(query,process){ var query = {query:query}
ProductName
的输入框
$('#ProductName').typeahead({
source: function(query,process){
var query = {query:query};
return $.post('/products/ajax_search_product_by_name',query,function(data){
return process(data.options);
},"json");
},
minLength: 3,
items: 50,
updater: function(item){
lastIndex = item.lastIndexOf('-');
length = item.length;
var product_id;
var product_name;
product_id = item.substr(lastIndex + 1, length);
product_name = item.substr(0,lastIndex);
document.getElementById('ProductName').value = product_name;
console.log(product_name);
}
我在文档中看到该项具有typeahead实例的范围:
The method used to return selected item. Accepts a single argument, the item and has the scope of the typeahead instance.
所以我尝试了这个
而不是使用DOM选择器,但它也不起作用。我还尝试了jQuery方式的$('#ProductName').val(产品名称)
,但没有成功
我在这里遗漏了什么吗?你在这里遗漏了什么:) updater方法不应该将值设置到输入中,而只是返回它。 实际值设置在调用更新程序方法后完成。 我相信,如果您将以以下方式结束您的更新程序方法:
return product_name;
它应该可以正常工作。您在这里遗漏了一些东西:) updater方法不应该将值设置到输入中,而只是返回它。 实际值设置在调用更新程序方法后完成。 我相信,如果您将以以下方式结束您的更新程序方法:
return product_name;
它应该很好用