I've a Bean with an ArrayList Languages. With languages.getname(index) I can get the name (string) of the language with Bean.Lanuages.get(index).name
我有一个带有ArrayList语言的Bean。使用languages.getname(index)我可以使用Bean.Lanuages.get(index).name获取该语言的名称(字符串)。
I've saved the length -1 (because index starts with 0 and length with 1) of the ArrayList in numberofLanguages.
我在numberofLanguages中保存了ArrayList的长度-1(因为索引以0开头,长度为1)。
Now I'm trying to view the name of each language in a multiselectable which is built with a ng-repeat.
现在,我正在尝试查看多重选择中使用ng-repeat构建的每种语言的名称。
Important parts of my script.js:
我的script.js的重要部分:
var app = angular.module('myApp', [ 'ui.bootstrap' ]);
app.controller("LanguageCtrl", languageController);
function languageController($scope){{
$scope.range = function(min, max, step){
step = step || 1;
var input = [];
for (var i = min; i <= max; i += step) input.push(i);
return input;
};
};
}
Important parts of my .htmlx:
我的.htmlx的重要部分:
<div class="panel-group col-md-12" id="accordion" role="tablist"
aria-multiselectable="true">
<div ng-repeat="n in range(0,#{Bean.numberOfLanguages})">
<div class="panel panel-default">
<div class="panel-heading" role="tab">
<h4 class="panel-title">
<a role="button" data-toggle="collapse"
data-parent="#accordion" href="#lang-german"
aria-expanded="true" aria-controls="lang-german">
#{Bean.Languages.get($index).name}
</a>
</h4>
</div>
The ng:repeat works fine, I've two languages in my ArrayList and it displays the content two times, but it just shows the name of the first language two times. I've tested #{Bean.Languages.get(1).name, and then the name of the 2nd language is shown.
ng:repeat工作正常,我的ArrayList中有两种语言,它显示内容两次,但它只显示第一种语言的名称两次。我测试了#{Bean.Languages.get(1).name,然后显示了第二语言的名称。
But I don't want to hardcore it, because there will be much more languages in the future. So how can I get the current language?
但我不想强调它,因为将来会有更多的语言。那么我怎样才能获得当前的语言?
1 个解决方案
#1
0
$index starts from 0 not one. In your case language one is index 0 and language two index 1
$ index从0开始而不是一个。在您的情况下,语言一是索引0,语言二索引1
#1
0
$index starts from 0 not one. In your case language one is index 0 and language two index 1
$ index从0开始而不是一个。在您的情况下,语言一是索引0,语言二索引1