UI Bootstrap Typeahead 不返回异步值 [英] UI Bootstrap Typeahead not returning async values

查看:17
本文介绍了UI Bootstrap Typeahead 不返回异步值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 UI Bootstrap Typeahead 进行自动完成搜索,以从数据库中选择一个类别.

I am trying to do an autocomplete search using UI Bootstrap Typeahead to select a category from a database.

我已经建立了一个有 4 个类别的示例数据库,最后一个将包含一千多个类别.

I have set up an example database with 4 categories, the final one will contain more than a thousand categories.

当我开始输入时,搜索结果返回 4 行(所以某些东西肯定有效,因为我试图更改数据库中的行数,而搜索结果反映了总行数)但没有任何值.然而,我写的并不重要,所以它似乎并不匹配.

When I start typing, the search results return 4 rows (so something must be working, because I tried to change the number of rows in the DB and the search result mirrors the total number of rows) but with no value. However, it doesn't matter what I write so it doesn't seem to be matching.

HTML

<input class="form-control" type="text" name="category" id="category" placeholder="Search..." ng-model="asyncSelected" typeahead="name for name in getCdOnCat($viewValue)" typeahead-loading="loadingLocations" required>

controller.js

//Typeahead: Category Search
$scope.getCdOnCat = function (searchVal) {
    return dataFactory.getCdOnCategory(searchVal, globalVal_accessToken, globalVal_storeId).then(function (response) {
        console.log(response.data.categories);
        return response.data.categories;
    }, function (error) {
        console.log('Error: dataFactory.getCdOnCategory');
    });
};

service.js

app.factory("dataFactory", function ($http) {
var factory = {};

factory.getCdOnCategory = function (searchVal, accessToken, storeId) {
    return $http.get('data/getCdOnCategory.aspx?searchVal=' + searchVal + '&accessToken=' + accessToken + '&storeId=' + storeId)
};

return factory;
});

JSON

{ "categories":[ 
    { "name": "Clothes" }, 
    { "name": "Cypress" }, 
    { "name": "Citrus" }, 
    { "name": "Cats" } 
] }

推荐答案

请看这里 http:///plnkr.co/edit/F4n1kNOHfZ9f3Zz63x2P?p=preview

改变

<input class="form-control" type="text" name="category" id="category" 
 placeholder="Search..." ng-model="asyncSelected" 
 typeahead="name for name in getCdOnCat($viewValue)" typeahead-loading="loadingLocations" 
 required>

<input class="form-control" type="text" name="category" id="category" 
 placeholder="Search..." ng-model="asyncSelected" 
 typeahead="obj.name for obj in getCdOnCat($viewValue)" typeahead-loading="loadingLocations" 
 required>

这篇关于UI Bootstrap Typeahead 不返回异步值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆