简体   繁体   中英

Assigning $index to ng-model: AngularJS

I have a kendo multi select widget in my template, the code for which is given below.

<div ng-repeat="program in user.programs">
    <label class="label-multi">{{program.name}}:</label>
    <select kendo-multi-select="" k-option-label="'Select Services...'" k-data-text-field="'name'" k-data-value-field="'id'" k-data-source="services" k-ng-model="selectedServices" >
    </select>
</div>

Each user has several programs , and each program has some services . Now I want to show the services that are already associated with the program ie selectedServices which I initialize in my controller like so:

$scope.selectedServices = ["S1","S2"];

But the problem is that selectedServices vary for each program. I was thinking about doing something like selectedServices[0] , selectedServices[1] and so on using $index . How do I achieve this and how do assign values to these selectedServices in my controller? Wouldn't it be an array of arrays?

Why don't you add a selectedServices array to user.programs ?
For example:

$scope.user.programs.selectedServices = ["S1", "S2"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM