2015-05-12 22 views
1

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 = {}; 
 
    });

回答

3

你的價值觀不持久的原因是因爲他們被重寫:

<accordion-group heading="Model" is-open="selectedCar.make" is-disabled="!selectedCar.make"> 

is-open="selectedCar.make"實際上將設置selectedCar.makefalse一旦手風琴關閉屬性。

同樣適用於所有其他值。

這是一個工作plunker。 (也包含一些其他問題的修補程序,如對於selectedCar和東西不適當的數據綁定...)