如何传递逗号分隔字符串以选择Angular js中的选项

Par*_*ngh 0 javascript angularjs

我有这个Json:

        {
                "field_id": "4otBG",
                "label": "Fullness",
                "type": "dropdown",
                "props": {
                    "req": "true",
                    "options": "Empty-ish, Plenty of Seats, Few Seats, Standing, Packed Like Sardines"
                }
            }
Run Code Online (Sandbox Code Playgroud)

如何将选项传递给选择选项,因为它是逗号分隔的字符串请帮帮我..

A.B*_*A.B 5

假设您已经在$ scope.data中获得了数据

$scope.optionsplit =  $scope.data.props.options.split(',');
Run Code Online (Sandbox Code Playgroud)

在视野中

<select name="yourinput">
   <option ng-repeat="o in optionsplit" value="{{o}}">{{o}}</option>
<select>
Run Code Online (Sandbox Code Playgroud)

或者使用ng-options

<select ng-options="o for o in optionsplit">

</select>
Run Code Online (Sandbox Code Playgroud)

或者你可以为它做一个过滤器

filter('commaspliter', function() {
    return function(input) {
    return input.split(',');
    } 
  });
Run Code Online (Sandbox Code Playgroud)

在视野中

<select name="yourinput">
<option ng-repeat="o in data.props.options | commaspliter"></option>
 </select>
Run Code Online (Sandbox Code Playgroud)