1
我有一个对象在下面的格式返回:遍历中对象的项目,找到匹配和替换
[
{
"category": "Coach",
"phrase_original": "Training {{the team}} to develop their match skills by ensuring they are comfortable with {{defence techniques}}",
"phrase_filter": "Training {{group}} to develop their {{attribute}} skills by ensuring they are comfortable with {{factor}}"
},
{
"category": "Coach",
"phrase_original": "Assisting the {{fitness coach}} in strength and conditioning work to improve {{team performance}}",
"phrase_filter": "Assisting the {{person}} in strength and conditioning work to improve {{factor}}"
}
]
我想通过每个解析并替换:
{{group}}
在phrase_filter
与<span style="group*button">group</span>
在
{{attribute}}
与<span style="attribute-button">group</span>
- 在
phrase_filter
与phrase_filter
<span style="factor-button">group</span>
- 与
<span style="person-button">person</span>
phrase_filter
什么是解决这个问题的最好方法?
这是我的代码到目前为止,我不确定是否实现上述。我目前正在从API端点获取数据,但不知道如何处理它。
CategoryService.getCategoryDetail($scope.categoryId).then(function(dataResponse) {
$scope.categoryDetail = dataResponse.data;
angular.forEach($scope.categoryDetail, function(e) {
// 1. find all the words in braces in phrase_filter
// 2. replace them with html markup so they are rendered in the view differently
// e.phrase_filter = ???
});
});
你应该添加angularjs作为标记;)但你也可以在纯JS –