admin管理员组文章数量:1404923
I have this Json:
{
"field_id": "4otBG",
"label": "Fullness",
"type": "dropdown",
"props": {
"req": "true",
"options": "Empty-ish, Plenty of Seats, Few Seats, Standing, Packed Like Sardines"
}
}
How to pass the Options to an selection option , because it is a ma separated string Please help me..
I have this Json:
{
"field_id": "4otBG",
"label": "Fullness",
"type": "dropdown",
"props": {
"req": "true",
"options": "Empty-ish, Plenty of Seats, Few Seats, Standing, Packed Like Sardines"
}
}
How to pass the Options to an selection option , because it is a ma separated string Please help me..
Share Improve this question edited Dec 23, 2014 at 20:33 A.B 20.5k3 gold badges42 silver badges73 bronze badges asked Dec 23, 2014 at 18:18 Parvindra SinghParvindra Singh 532 silver badges10 bronze badges 1- Repeated stackoverflow./questions/19718609/split-for-ng-repeat-item – Carlos Verdes Commented Dec 23, 2014 at 18:44
2 Answers
Reset to default 5Assuming that you have got you data in $scope.data
$scope.optionsplit = $scope.data.props.options.split(',');
In view
<select name="yourinput">
<option ng-repeat="o in optionsplit" value="{{o}}">{{o}}</option>
<select>
Or with ng-options
<select ng-options="o for o in optionsplit">
</select>
or you can make a filter for it
filter('maspliter', function() {
return function(input) {
return input.split(',');
}
});
In view
<select name="yourinput">
<option ng-repeat="o in data.props.options | maspliter"></option>
</select>
The angular way would be to use a filter. Note you're not supposed to use $
prefix, but since this is such a general purpose filter I thought it was appropriate. Feel free to rename.
.filter('$split', function() {
return function(val, splitter) {
if (!splitter) { splitter = ','; }
return (val && val.length) ? val.split(splitter) : [];
}
});
Use it like so.
<select ng-options="val for val in props.options | $split" />
You can even pass an additional param if you have data that is delimited by a different character.
<select ng-options="val for val in props.options | $split:'|'" />
本文标签: javascriptHow to pass a Comma seperated String to select options in Angular jsStack Overflow
版权声明:本文标题:javascript - How to pass a Comma seperated String to select options in Angular js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744878250a2630046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论