newbie newbie - 24 days ago 10
Java Question

Angularjs How to show hidden data from the selected row in a listBox?

i got something like this:

A table, with the data of more students...the content is ID, Name, LastName and From.....now i added a new class to the project...its called BankAccount

the students can have 0 or more accounts...

and i added them in a data-binding process to the students...

now i want to select a student, and to show his (if any) accounts in a listBox on the same page...so far i have this code:

the table with the students...

<table border="1" name="tableStud" arrow-selector>
<tbody>
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>From</td>
</tr>

<tr ng-repeat="student in result"
ng-class="{'selected':$index == selectedRow}"
ng-click="setSelected(student,$index)">
<td>{{ student.id }}</td>
<td>{{ student.firstname }}</td>
<td>{{ student.lastname }}</td>
<td>{{ student.mestorodjenja.ime }}</td>

</tr>

</tbody>
</table>


<select ng-model="student.accounts" multiple="multiple"
ng-options="account.name for account in student.accounts track by account.id"

>
</select>


In the controler i got this:

$scope.setSelected = function(student, index) {
$scope.student = student;
$scope.selectedRow = index;
};


Now the problem is, my list box is showing the accounts for the selected students....but they are all SELECTED and, once i press on one of them, the others disappear, while the pressed one is still selected....

On top of that, once i go on to another student, and come back...all the disappeared accounts from the listBox are still missing....and the old one is also selected...

In the end my question is:

Is it possible to just select the student, and his accounts to be shown on the listBox without being selected....and not disappearing after i press them...?

Thx in advance!

Answer

Just replace your varible for selected student. Like :

$scope.setSelected = function(student, index) {
   $scope.selectedstudent = student;   
   $scope.selectedRow = index;
};

HTML :

 <select ng-model="student.accounts" multiple="multiple"
            ng-options="account.name for account in selectedstudent.accounts track by account.id"

    >
    </select>
Comments