【问题标题】:Angular ui-select model bindingAngular ui-select 模型绑定
【发布时间】:2016-05-20 17:18:32
【问题描述】:

我在范围内有以下对象

$scope.myData = {};
$scope.companies =    [{name:'Microsoft',slug:'micro'},
                {name:'Google',slug:'gg'}];

我正在尝试使用 ui-select 将 slug 绑定到模型

<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 绑定到 myData.company 但能够按公司名称搜索?

【问题讨论】:

    标签: javascript angularjs ui-select


    【解决方案1】:

    感谢this,我终于找到了怎么做,为了让它工作,&lt;ui-select-choices&gt;应该改变如下;

    <ui-select-choices repeat="company.slug as company in companies | filter: $select.search">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-03
      • 2015-02-03
      相关资源
      最近更新 更多