Über Objekte im Objekt iterieren, Übereinstimmungen finden und @ ersetz
Ich habe ein Objekt im folgenden Format zurückgegeben:
[
{
"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}}"
}
]
Ich möchte jede einzelne analysieren und ersetzen:
{{group}}
imphrase_filter
mit<span style="group*button">group</span>
{{attribute}}
imphrase_filter
mit<span style="attribute-button">group</span>
{{factor}}
imphrase_filter
mit<span style="factor-button">group</span>
{{person}}
imphrase_filter
mit<span style="person-button">person</span>
Was wäre der beste Weg, um dies zu erreichen?
Dies ist mein Code, ich bin nicht sicher, ob ich den obigen implementieren soll. Ich erhalte derzeit die Daten vom API-Endpunkt, weiß aber noch nicht, wie ich sie verarbeiten soll.
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 = ???
});
});