2015-01-26 96 views
1

的數組值我有一個看起來像這樣的列表:獲取角度NG重複

Store 1 
    Section A 
    Section B 
    and so on... 
Store 2 
    Section A 
    and so on... 

於是我打開一個模式窗口來創建一個新的商店。當我關上窗戶時,我將商店歸還,到目前爲止效果很好!

<div ng-repeat="store in global.user.company2.store"> 

我需要回調店推到scope.global.user.company2.store $ [?]

modalInstance.result.then(function (newStore) { 
    // How do I get the IndexOf value of store? 
    // This is one of the stores in the ng-repeat 
    $scope.global.user.company2.store[???].section.push(newStore) 
}, function() { 
    $log.info('Modal dismissed at: ' + new Date()); 
}); 

我送一個選擇的店,變成模態的方式與決心

$scope.createSection = function (size) { 

     var modalInstance = $modal.open({ 
      templateUrl: 'createSection.html', 
      controller: 'SectionModal', 
      size: size, 
      resolve: { 
       items: function() { 
        // $scope.radio.model === store 
        // $scope.radio.model2 === section 
        return $scope.radio; 
       } 
      } 
     }); 

更新:這是一個基本的plunker http://plnkr.co/edit/UGN4niAO9nQETqhg8lxn 無線電模型按鈕不起作用。如果您將解析項目更改爲$ scope.radio.model,則模式會中斷。所以我把它留下了。我想也許它是與作爲angular-ui-bootstrap一部分的btn-radio有關的?

+0

你可以做一個小提琴嗎? – 2015-01-26 20:25:22

+0

我會盡力做出一個! – 2015-01-26 20:25:46

+0

請發佈一個plunker,這裏是一個角模板,讓你開始:http://plnkr.co/edit/WprgipAdFBtxDKM6jogo?p=info – SoluableNonagon 2015-01-26 20:26:13

回答

1

當解析你的模態時,將你的返回對象與對象的數組索引一起裝箱。
例如:

$modalInstance.close({ radio: $scope.radio, index: $scope.items.indexOf($scope.radio) }); 

然後,解決您的情態的承諾之時,要拆箱您的對象:

modalInstance.result.then(function (selectedItem) { 
     $scope.selected = selectedItem.radio; 
     $scope.selectedIndex = selectedItem.index; 
}, function() {}); 

見角引導docs瞭解更多詳情。

+1

謝謝!有效! – 2015-01-26 22:02:41