范围内有以下对象
$scope.myData = {};
$scope.companies = [{name:'Microsoft',slug:'micro'},
{name:'Google',slug:'gg'}];
我正在尝试使用 ui-select 将 slug 绑定(bind)到模型
<div class="form-group">
<label>Company</label>
<ui-select ng-model="$parent.myData.company" theme="bootstrap">
<ui-select-match placeholder="Select or search a company in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices repeat="company in companies | filter: $select.search">
<div ng-bind-html="company.name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
</div>
但是,当我选择一家公司时,myData.company 变成了完整的对象,例如。 {"name":"Microsoft","slug":"micro"}
如何将公司对象的 slug
绑定(bind)到 myData.company 但能够按公司名称搜索?
最佳答案
感谢 this,我终于找到了解决方法为了让它工作,<ui-select-choices>
应更改如下;
<ui-select-choices repeat="company.slug as company in companies | filter: $select.search">
关于javascript - Angular ui-select模型绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37342392/