我有一个AngularJS Typeahead以异步方式检索匹配项。当条形码扫描到现场时,它会返回匹配结果,但用户仍然必须选择它。如果它完全匹配,我想自动选择结果。我看到typeahead有一个select(idx)函数,但不知道如何从我的控制器获取对它的引用。以编程方式选择AngularJS Typeahead选项
我设想是这样的:
$scope.SearchItems = function (term) {
return $http.get('api/Items/Search', {
params: {
term: term
}
}).then(function (response) {
if (response.data.length == 1 && response.data[0].Code == term) {
// Somehow inform typeahead control to select response.data[0]
}
return response.data;
});
};
请问您可以添加一个console.log(响应)并让我知道它返回什么? – Nicolas2bert 2015-10-09 22:13:24
{ 配置:{...}, 数据:[{代码= “ABC”,OtherProperties =值}], 状态:200, 状态文本: “OK” } – 2015-10-11 04:28:58