angularjs translate 以所选语言显示键值
angularjs translate display the value of the key in the chosen language
我的 i18n 翻译文件中有以下数据:
"mylist" : {
"fruits": [
{
"key": "A",
"value": "Apple"
},
{
"key": "B",
"value": "Banana"
}
]
}
在我的标记中,我是这样理解的:
<ui-select ng-model="user.fruits" name="fruits" theme="selectize">
<ui-select-match>{{$select.selected.value}}</ui-select-match>
<ui-select-choices repeat="f.key as f in transl.mylist.fruits | filter: $select.search">
<div ng-bind-html="f.value | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
在我的标记中,我是这样读的:
<td>{{user.fruits}}</td>
所以我在输出中看到了key
,因为我已经将密钥存储在ng-model中,因为我有多种语言,所以我想存储相同的密钥,但为每种所选语言显示不同的值。
现在的问题是:
如何以所选语言显示键的值?
以便显示 value
而不是密钥。我如何在翻译文件中查找它?
添加在列表中搜索所选键的功能
$scope.displaySelectedValue = function(option) {
for(var i=0; i <transl.mylist.fruits.length; i++) {
if(mylist.fruits[i].key === option)
return mylist.fruits[i].value;
}
}
调用传递选定水果值的函数
<td>{{displaySelectedValue(user.fruits)}}</td>
我的 i18n 翻译文件中有以下数据:
"mylist" : {
"fruits": [
{
"key": "A",
"value": "Apple"
},
{
"key": "B",
"value": "Banana"
}
]
}
在我的标记中,我是这样理解的:
<ui-select ng-model="user.fruits" name="fruits" theme="selectize">
<ui-select-match>{{$select.selected.value}}</ui-select-match>
<ui-select-choices repeat="f.key as f in transl.mylist.fruits | filter: $select.search">
<div ng-bind-html="f.value | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
在我的标记中,我是这样读的:
<td>{{user.fruits}}</td>
所以我在输出中看到了key
,因为我已经将密钥存储在ng-model中,因为我有多种语言,所以我想存储相同的密钥,但为每种所选语言显示不同的值。
现在的问题是:
如何以所选语言显示键的值?
以便显示 value
而不是密钥。我如何在翻译文件中查找它?
添加在列表中搜索所选键的功能
$scope.displaySelectedValue = function(option) {
for(var i=0; i <transl.mylist.fruits.length; i++) {
if(mylist.fruits[i].key === option)
return mylist.fruits[i].value;
}
}
调用传递选定水果值的函数
<td>{{displaySelectedValue(user.fruits)}}</td>