Mic*_*son 3 javascript angularjs
我希望以$index字母格式输出而不是编号.
<div ng-repeat="name in names">{{$index}}</div>
这可能吗?
这是我找到的解决方案:
使用Javascript:
// the alphabet
$scope.alphabet['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
// get the index and return the letter of the alphabet
$scope.getLetter = function(index) {
return $scope.alphabet[index];
};
Run Code Online (Sandbox Code Playgroud)
HTML:
<div ng-repeat="name in names">{{getLetter($index)}}</div>
Run Code Online (Sandbox Code Playgroud)
编辑(感谢@TheShalit和@patrick):
使用Javascript:
// get the index and return the letter of the alphabet
$scope.getLetter = function(index) {
return String.fromCharCode(65+index);
};
Run Code Online (Sandbox Code Playgroud)
HTML:
<div ng-repeat="name in names">{{getLetter($index)}}</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1332 次 |
| 最近记录: |