UI引导键盘缓冲没有返回值异步返回值、键盘、UI

2023-09-14 00:19:41 作者:风吹裤裆毛飞扬

我试图做使用UI引导键盘缓冲选择从数据库类别自动完成搜索。

我已经建立了一个数据库实例与4类,最后一节将包含一千多个类别。

当我开始打字,搜索结果中返回4行(这样的东西必须正常工作,因为我试图改变在数据库和搜索结果的行数反映行的总数),但没有价值。不过,没关系,我似乎写的有啥不被匹配。

HTML

 <输入类=表格控型=TEXTNAME =类别ID =类别占位=搜索...NG-模式= asyncSelected预输入=的名字在ge​​tCdOnCat($ viewValue)名称为预输入加载=loadingLocations要求> 

controller.js

  //键盘缓冲:分类搜索$ scope.getCdOnCat =功能(searchVal){    返回dataFactory.getCdOnCategory(searchVal,globalVal_accessToken,globalVal_storeId)。然后(功能(响应){        的console.log(response.data.categories);        返回response.data.categories;    },功能(错误){        的console.log('错误:dataFactory.getCdOnCategory');    });}; 
按键精灵function返回值如何设置 function返回值设置流程图文介绍

service.js

  app.factory(的DataFactory功能($ HTTP){变种工厂= {};factory.getCdOnCategory =功能(searchVal,的accessToken,STOREID){    返回$ http.get(数据/ getCdOnCategory.aspx searchVal ='+ searchVal +'和;的accessToken ='+的accessToken +'和​​; STOREID ='+ STOREID)};回厂;}); 

JSON

  {类别:    {名:衣服},    {名:赛扬preSS},    {名:柑橘},    {名:猫}]} 

解决方案

请在这里看到 http://plnkr.co/edit/F4n1kNOHfZ9f3Zz63x2P?p=$p$pview

变更

 <输入类=表格控型=TEXTNAME =类别ID =类别占位=搜索...NG-模式= asyncSelected预输入=的名字在ge​​tCdOnCat($ viewValue)名称为预输入加载=loadingLocations要求> 

 <输入类=表格控型=TEXTNAME =类别ID =类别占位=搜索...NG-模式= asyncSelected预输入=obj.name在getCdOnCat($ viewValue)目标文件预输入加载=loadingLocations要求> 

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

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

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" } 
] }

解决方案

Please see here http://plnkr.co/edit/F4n1kNOHfZ9f3Zz63x2P?p=preview

change

<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>

to

<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>