我正在使用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"]
可能是什么问题?
答案 0 :(得分:2)
改变1:
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>