我有这个 Json:
{
"field_id": "4otBG",
"label": "Fullness",
"type": "dropdown",
"props": {
"req": "true",
"options": "Empty-ish, Plenty of Seats, Few Seats, Standing, Packed Like Sardines"
}
}
如何将选项传递给选择选项,因为它是逗号分隔的字符串请帮助我..
最佳答案
假设您已在 $scope.data 中获取数据
$scope.optionsplit = $scope.data.props.options.split(',');
在 View 中
<select name="yourinput">
<option ng-repeat="o in optionsplit" value="{{o}}">{{o}}</option>
<select>
或者使用 ng-options
<select ng-options="o for o in optionsplit">
</select>
或者你可以为其制作一个过滤器
filter('commaspliter', function() {
return function(input) {
return input.split(',');
}
});
在 View 中
<select name="yourinput">
<option ng-repeat="o in data.props.options | commaspliter"></option>
</select>
关于javascript - 如何传递逗号分隔的字符串来选择 Angular js 中的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27625894/