簡體   English   中英

ui-select multiple:ng-model如何將其保存為字符串而不是數組

[英]ui-select multiple: ng-model how will it be saved as string and not as array

我有這個用戶界面選擇:

<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' ... ] 

它在帶有角ng-repeat的簡單表中

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

我用它過濾:

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

問題是這樣的:當我選擇一個對象然后取消選擇它時,“ daySelected”模型將變成一個數組。 角度過濾器只是將其消除並過濾。 所以我需要以下2項之一的幫助:

  1. make daySelected作為字符串(選擇時為:“ sun,mon”或
  2. 調整過濾器以在數組中工作

假設搜索文本將類似於“ Mon,Tue”,它將過濾具有[“ Mon”,“ Tue”]的所有ui選擇,您可以編寫自己的過濾器函數並將其傳遞。 例如:

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

在您的控制器中,您需要創建該函數:

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

您需要在哪里:

  • 將搜索條件的值除以“,”
  • 驗證拆分數組中的每個項目是否存在於函數值參數中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM