在 md-autocomplete 中搜索时如何更改选项
How to change options when searching in md-autocomplete
如何在输入时更改选项。当我输入过滤器时它无法正常工作它显示我想要的所有列表根据搜索更改列表文本请帮助我。
<md-autocomplete
ng-disabled="Ctrlmain.isDisabled"
md-no-cache="Ctrlmain.noCache"
md-selected-item="Ctrlmain.selectedItem"
md-search-text="Ctrlmain.campaignname"
md-selected-item-change="Ctrlmain.filltextbox(item)"
md-items="item in Ctrlmain.getMatches(Ctrlmain.campaignname) | unique:'campaign_name'"
md-item-text="item.campaign_name"
md-min-length="0"
placeholder="Pick an Angular repository"
md-menu-class="autocomplete-custom-template">
<md-item-template>
<span class="item-title">
<span> {{item.campaign_name}} </span>
</span>
</md-item-template>
</md-autocomplete>
Angular 方法
complete(str){
var output = [];
angular.forEach(this.viewData,function(campaignname){
if(campaignname.campaign_name.toLowerCase().indexOf(str.toLowerCase())>=0){
output.push(campaignname.campaign_name);
};
});
return output.campaign_name;
}
filltextbox(st){
return st;
}
在 md-search-text-change
上返回匹配项无效。您的 md-autocomplete
已绑定到 Ctrlmian.viewData
。如果那行得通,您必须修改 complete
函数末尾的所述数组。此外,当您尝试 return output.campaign_name
时,您的代码本质上是错误的,其中 output
是一个数组。或者你也可以这样试试...
<md-autocomplete
ng-disabled="Ctrlmain.isDisabled"
md-no-cache="Ctrlmain.noCache"
md-selected-item="Ctrlmain.selectedItem"
md-search-text="Ctrlmain.campaignname"
md-selected-item-change="Ctrlmain.filltextbox(item)"
md-items="item in Ctrlmain.getMatches(Ctrlmain.campaignname) | unique:'campaign_name'"
md-item-text="item.campaign_name"
md-min-length="0"
placeholder="Pick an Angular repository"
md-menu-class="autocomplete-custom-template">
<md-item-template>
<span class="item-title">
<span> {{item.campaign_name}} </span>
</span>
</md-item-template>
</md-autocomplete>
注意我已经摆脱了 md-search-text-change
。我正在使用您的过滤器功能为 md-autocomplete
动态呈现项目,如下所示。
getMatches(str) {
var output = [];
angular.forEach(this.viewData,function(campaignname) {
if(campaignname.campaign_name.toLowerCase().indexOf(str.toLowerCase())>=0) {
output.push(campaignname);
};
});
return output;
}
如何在输入时更改选项。当我输入过滤器时它无法正常工作它显示我想要的所有列表根据搜索更改列表文本请帮助我。
<md-autocomplete
ng-disabled="Ctrlmain.isDisabled"
md-no-cache="Ctrlmain.noCache"
md-selected-item="Ctrlmain.selectedItem"
md-search-text="Ctrlmain.campaignname"
md-selected-item-change="Ctrlmain.filltextbox(item)"
md-items="item in Ctrlmain.getMatches(Ctrlmain.campaignname) | unique:'campaign_name'"
md-item-text="item.campaign_name"
md-min-length="0"
placeholder="Pick an Angular repository"
md-menu-class="autocomplete-custom-template">
<md-item-template>
<span class="item-title">
<span> {{item.campaign_name}} </span>
</span>
</md-item-template>
</md-autocomplete>
Angular 方法
complete(str){
var output = [];
angular.forEach(this.viewData,function(campaignname){
if(campaignname.campaign_name.toLowerCase().indexOf(str.toLowerCase())>=0){
output.push(campaignname.campaign_name);
};
});
return output.campaign_name;
}
filltextbox(st){
return st;
}
在 md-search-text-change
上返回匹配项无效。您的 md-autocomplete
已绑定到 Ctrlmian.viewData
。如果那行得通,您必须修改 complete
函数末尾的所述数组。此外,当您尝试 return output.campaign_name
时,您的代码本质上是错误的,其中 output
是一个数组。或者你也可以这样试试...
<md-autocomplete
ng-disabled="Ctrlmain.isDisabled"
md-no-cache="Ctrlmain.noCache"
md-selected-item="Ctrlmain.selectedItem"
md-search-text="Ctrlmain.campaignname"
md-selected-item-change="Ctrlmain.filltextbox(item)"
md-items="item in Ctrlmain.getMatches(Ctrlmain.campaignname) | unique:'campaign_name'"
md-item-text="item.campaign_name"
md-min-length="0"
placeholder="Pick an Angular repository"
md-menu-class="autocomplete-custom-template">
<md-item-template>
<span class="item-title">
<span> {{item.campaign_name}} </span>
</span>
</md-item-template>
</md-autocomplete>
注意我已经摆脱了 md-search-text-change
。我正在使用您的过滤器功能为 md-autocomplete
动态呈现项目,如下所示。
getMatches(str) {
var output = [];
angular.forEach(this.viewData,function(campaignname) {
if(campaignname.campaign_name.toLowerCase().indexOf(str.toLowerCase())>=0) {
output.push(campaignname);
};
});
return output;
}