对象值不会持久化

时间:2015-05-12 21:58:34

标签: angularjs accordion angular-ui-bootstrap

http://plnkr.co/edit/KEhcaEs2GptBlF60KAXi?p=preview

我试图在每组中创建一个有多个选项的手风琴。 一旦在组中进行选择,则启用并扩展其下方的组以允许下一个选择。 我让UI工作,但是当我存储选择时,每次选择时都会覆盖它。

如何保留所选值?



angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function ($scope) {

    $scope. oneAtATime = true;

    $scope.selectedCar = {
        make: null,
        model: null,
        year: null,
        comments: null
    }

    $scope.setSelectedCar = function (key, value) {
        $scope.selectedCar[key] = value;
    }

    $scope.status = {
        isFirstOpen: true,
        isFirstDisabled: false
    };

    $scope.cars = {};
  });




1 个答案:

答案 0 :(得分:3)

The reason your values do not persist is because they are being overriden:

if (bacteriaStrand[0] == 'A') {
    int totalLength = cornStrand.length + bacteriaStrand.length;
    char [] combinedStrand = new char [totalLength];
    for(int i=0; i<cornStrand.length; i++){
         combinedStrand[i] = cornStrand[i]; //fill in corn until you find the first G
         if (cornStrand[i] == 'G') {
            int j = 0;
            for(; j<bacteriaStrand.length; j++){
                combinedStrand[i+j+1] = bacteriaStrand[j]; //fill in bacteria
            }
            i++;
            for(;i<cornStrand.length;i++){
                combinedStrand[i+j+1] = cornStrand[i] //fill in the rest of corn
            }
         }                
    }//now this loop will break, since you increased i, so you won't get duplicates
}

The attribute <accordion-group heading="Model" is-open="selectedCar.make" is-disabled="!selectedCar.make"> will actually set is-open="selectedCar.make" to selectedCar.make once the accordion is closed.

Same goes for all other values.

Here's a working plunker. (also containing fixes to a few other problems like inappropriate data-binding for false and stuff...)