ui-select multiple:ng-model如何将其保存为字符串而不是数组

问题描述 投票:0回答:1

我有这个ui选择:

<ui-select multiple
    ng-model="meas.daysSelected"
    theme="bootstrap"
    close-on-select="false">
    <ui-select-match placeholder="days">{{$item}}</ui-select-match>
    <ui-select-choices repeat="day in days | filter:$select.search">
        <div ng-bind-html="day | highlight: $select.search"></div>
    </ui-select-choices>
</ui-select>

$scop.days = ['Sun', 'Mon', 'Tue' ... ] 

它位于一个带有角度重复的简单表格中

<tr ng-repeat="meas in foo= (res.foos | filter: subSearch : strict)">

我过滤它:

<input type="text" class="form-control" ng-model="subSearch.daysSelected">

问题是这样的:当我选择一个对象然后取消选择它时,“daySelected”模型正在变成一个数组。角度过滤器只是将它解散并过滤它。所以我需要帮助2:

  1. 将daySelected设为字符串(选中时将为:“sun,mon”或
  2. 调整过滤器以在数组中工作
angularjs ui-select angular-ui-select
1个回答
1
投票

假设搜索文本将像“Mon,Tue”,它将过滤所有具有[“Mon”,“Tue”]的ui选择,你可以编写自己的过滤函数并传递它。例如:

<tr ng-repeat="meas in foo= (res.foos | filter: $ctrl.filterDaysSelected">

在您的控制器中,您需要创建该功能:

$ctrl.filterDaysSelected = function(value, index, array) {}

你需要在哪里:

  • 将搜索条件的值拆分为“,”
  • 验证split数组中的每个项目是否存在于函数值参数中
© www.soinside.com 2019 - 2024. All rights reserved.