Angular 自动完成 returns 空白列表
Angular auto complete returns a blank list
我正在使用 AngularJS 创建自动完成。将使用 json 提供自动完成的值列表。在我的应用程序中,当我开始输入时,我得到一个空列表。所有的值都是空白的。这是我的视图代码:
<md-autocomplete flex required
md-input-name="un_registered[vehicle_attributes][brand_name]"
md-no-cache="mainCtrl.noCache"
md-selected-item-chang=""
md-search-text-change=""
md-selected-item="mainCtrl.selectedItem"
md-search-text="mainCtrl.searchText"
md-items="item in mainCtrl.querySearch(mainCtrl.searchText)"
md-item-text="item.display"
md-floating-label="Brand" id="un_registered_vehicle_attributes_brand_name">
<md-item-template>
<span md-highlight-text="mainCtrl.searchText">{{item.display}}</span>
</md-item-template>
<div ng-messages="searchForm.autocompleteField.$error" ng-if="searchForm.autocompleteField.$touched">
<div ng-message="required">You <b>must</b> have a favorite state.</div>
<div ng-message="minlength">Your entry is not long enough.</div>
<div ng-message="maxlength">Your entry is too long.</div>
</div>
</md-autocomplete>
这是我的 querySearch
函数:
mainCtrl.querySearch = querySearch;
function querySearch(query) {
return $http.get("/panel/all_brands.json")
.then(function(result) {
return result;
});
}
我的json数据:
["Example Brand","abcdd","Example Brand2Hh","rr","ffff"]
可能是什么问题?
变化一:
function querySearch(query) {
$http.get("/panel/all_brands.json").success(
function(data, status, headers, config) {
mainCtrl.TestData = data;
});
}
变化2:
md-search-text-change="mainCtrl.querySearch(mainCtrl.searchText)"
md-selected-item="mainCtrl.selectedItem"
md-search-text="mainCtrl.searchText"
md-items="item in mainCtrl.TestData | filter: mainCtrl.searchText"
变化 3:
<span md-highlight-text="mainCtrl.searchText">{{item}}</span>
我正在使用 AngularJS 创建自动完成。将使用 json 提供自动完成的值列表。在我的应用程序中,当我开始输入时,我得到一个空列表。所有的值都是空白的。这是我的视图代码:
<md-autocomplete flex required
md-input-name="un_registered[vehicle_attributes][brand_name]"
md-no-cache="mainCtrl.noCache"
md-selected-item-chang=""
md-search-text-change=""
md-selected-item="mainCtrl.selectedItem"
md-search-text="mainCtrl.searchText"
md-items="item in mainCtrl.querySearch(mainCtrl.searchText)"
md-item-text="item.display"
md-floating-label="Brand" id="un_registered_vehicle_attributes_brand_name">
<md-item-template>
<span md-highlight-text="mainCtrl.searchText">{{item.display}}</span>
</md-item-template>
<div ng-messages="searchForm.autocompleteField.$error" ng-if="searchForm.autocompleteField.$touched">
<div ng-message="required">You <b>must</b> have a favorite state.</div>
<div ng-message="minlength">Your entry is not long enough.</div>
<div ng-message="maxlength">Your entry is too long.</div>
</div>
</md-autocomplete>
这是我的 querySearch
函数:
mainCtrl.querySearch = querySearch;
function querySearch(query) {
return $http.get("/panel/all_brands.json")
.then(function(result) {
return result;
});
}
我的json数据:
["Example Brand","abcdd","Example Brand2Hh","rr","ffff"]
可能是什么问题?
变化一:
function querySearch(query) {
$http.get("/panel/all_brands.json").success(
function(data, status, headers, config) {
mainCtrl.TestData = data;
});
}
变化2:
md-search-text-change="mainCtrl.querySearch(mainCtrl.searchText)"
md-selected-item="mainCtrl.selectedItem"
md-search-text="mainCtrl.searchText"
md-items="item in mainCtrl.TestData | filter: mainCtrl.searchText"
变化 3:
<span md-highlight-text="mainCtrl.searchText">{{item}}</span>