将选项值设置为数组
set option value as array
正在设置一些权限。我希望能够将我的 item.roles 设置为一个数组。这可能吗?如果不是,让我的 item.roles 模型最终成为数组的最明智的方法是什么?
<select class="form-control" ng-model="item.roles" ng-init="item.roles[0]='client'">
<option value="[super, admin, producer, resource, client]">Super</option>
<option value="[admin, producer, resource, client]">Admin</option>
<option value="[producer, resource, client]">Producer</option>
<option value="[resource, client]">Resource</option>
<option value="[client]">Client</option>
</select>
您可以使用 ngList 指令:
<select class="form-control" ng-list ng-model="item.roles" ng-init="item.roles=['client']">
<option value="super, admin, producer, resource, client">Super</option>
<option value="admin, producer, resource, client">Admin</option>
<option value="producer, resource, client">Producer</option>
<option value="resource, client">Resource</option>
<option value="client">Client</option>
</select>
请注意,本例中的选项值是逗号分隔列表(或者您可以更改分隔符)。
ngList
指令用于转换分隔值列表 to/from 数组:
Text input that converts between a delimited string and an array of strings. The default delimiter is a comma followed by a space - equivalent to ng-list=", ". You can specify a custom delimiter as the value of the ngList attribute - for example, ng-list=" | ".
正在设置一些权限。我希望能够将我的 item.roles 设置为一个数组。这可能吗?如果不是,让我的 item.roles 模型最终成为数组的最明智的方法是什么?
<select class="form-control" ng-model="item.roles" ng-init="item.roles[0]='client'">
<option value="[super, admin, producer, resource, client]">Super</option>
<option value="[admin, producer, resource, client]">Admin</option>
<option value="[producer, resource, client]">Producer</option>
<option value="[resource, client]">Resource</option>
<option value="[client]">Client</option>
</select>
您可以使用 ngList 指令:
<select class="form-control" ng-list ng-model="item.roles" ng-init="item.roles=['client']">
<option value="super, admin, producer, resource, client">Super</option>
<option value="admin, producer, resource, client">Admin</option>
<option value="producer, resource, client">Producer</option>
<option value="resource, client">Resource</option>
<option value="client">Client</option>
</select>
请注意,本例中的选项值是逗号分隔列表(或者您可以更改分隔符)。
ngList
指令用于转换分隔值列表 to/from 数组:
Text input that converts between a delimited string and an array of strings. The default delimiter is a comma followed by a space - equivalent to ng-list=", ". You can specify a custom delimiter as the value of the ngList attribute - for example, ng-list=" | ".