我试图将一个字符串解析为一个字符数组,用<span></span>
围绕每个字符。提交解析的函数有效,每个char都包含<span>
标记。
要解析的函数:
app.controller('tableCtrl',function($scope,$sce) {
//parse cron_format and edit each digit individually
$scope.parse = function (cron_format){
var parsed = cron_format.split(" ");
for(var i = 0; i < parsed.length; i++) {
parsed[i] = '<span>' + parsed[i] + '</span>';
}
$scope.parsedCron = $sce.trustAsHtml(parsed.toString());
return $scope.parsedCron;
}
});
我在<td>
这个字符串中得到的内容:
<span>*/3</span>,<span>*</span>,<span>*</span>,<span>*</span>,<span>*</span>
为什么赢得<span>
呈现?
这是我试图添加结果的表:
<tbody ng-repeat="(user_id,script_id) in data | filter: test">
<tr ng-repeat="(script_id, cron_format) in script_id">
<td>{{user(user_id)}}</td>
<td>{{script(script_id)}}</td>
**<td>{{parse(cron_format)}}</td>**
</tr>
</tbody>
答案 0 :(得分:1)
app.controller('tableCtrl',function($scope) {
$scope.letters = function(cron_format){
return cron_format.split('');
}
}});
模板:
<tbody ng-repeat="(user_id,script_id) in data | filter: test">
<tr ng-repeat="(script_id, cron_format) in script_id">
<td>{{user(user_id)}}</td>
<td>{{script(script_id)}}</td>
**<td><span ng-repeat="l in letters(cron_format)">{{l}}</span></td>**
</tr>
</tbody>