2017-02-28 59 views
0

我在角形式有一个多选场:角:格式保存和加载多个选择数据

<div crm-ui-field="{name: 'subform.committees', title: ts('Secondary Committee')}"> 
    <div ng-controller="CommitteeCtrl"> 
    <select 
     multiple="multiple" 
     crm-ui-id="subform.committees" 
     name="secondary_committee" 
     crm-ui-select="{dropdownAutoWidth : true, allowClear: false, placeholder: ts('Choose Committee')}" 
     ng-model="mailing.secondary_committee" 
     ng-options="comm as comm.label for comm in comms track by comm.value" 
    > 
     <option /> 
    </select> 
    </div> 
</div> 

我遇到问题,试图找出如何存储数据和检索它,这样角度形式正确加载值。角度如何看待数据?

+1

这[一](https://docs.angularjs.org/api/ng/directive/select)怎么样? – mbeso

回答

1

对于多选NG-模型是一个Array, 同时发送到后端你需要做[]作为字符串,然后它会融入在DB一列:

var secondaryCommitteeStr = $scope.mailing.secondary_committee.join(','); 

所以在检索,您需要将模型数据设置为选定实体的阵列,然后角将自动填充选择实体的$scope.mailing.secondary_committee

$scope.mailing.secondary_committee = data.split(',');// service data 
+0

是的,在检索步骤中,我没有将其转换回数组,这导致了问题。 – lcdservices