2016-12-26 66 views
0

我显示json的数据。 我想替换其他值(翻译)。 这就像:从json替换值

<li ng-repeat="childrens in data.children track by $index"> 
     <a>{{childrens.type}}</a> 
    </li> 

在“类型”我可以有“QUOTE”,“条例”或“存款” ...... 我想替换翻译此值。

但我是角度初学者,我也是第一次在json上工作,有什么更好的方法来做到这一点?

我试图用fonction替换()在我的控制器,但是,这并不工作:

if($scope.children.type =='QUOTE'){ 
     $scope.children.type = $scope.children.type.replace('Facture'); 
    } 

感谢您的帮助球员:)

+0

为翻译更好的使用[角度翻译](https://angular-translate.github.io) – IARKI

+0

我需要翻译理由3个单词,所以也许它不足以使用角度翻译? ^^ –

回答

1

你可以这样做:

<li ng-repeat="childrens in data.children track by $index"> 
    <a>{{mapObject[childrens.type].text}}</a> 
</li> 

在控制器中,您可以使用javascript地图

$scope.mapObject = { 
    "QUOTE":{ 
    "text":"Facture" 
    } 
} 
+0

完美的工作!非常感谢 ! :) –