0

我有一個彈出框中的選擇框,我沒有任何問題地分配一個初始值。但是,當我打開彈出窗口時,我想要更改選擇框的值,儘管它會「更改」已更改的值,但它不會顯示在選擇框中,除非我再次打開並關閉彈出窗口。任何解決方案,使選擇框更新,以便當我第一次打開彈出窗口分配的值顯示?以編程方式更改模型時選擇框未更新

注:在生產中我使用angularJs來填充選擇框和jqmobile來呈現它。

這裏是小提琴和代碼:https://jsfiddle.net/AKMorris/ufcasngf/6/

<button ng-click="openPopup()">open popup</button> 
    <div data-role="popup" id="mypopup" data-overlay-theme="d" data-theme="none"> 
    <select id="fcComparator" 
      ng-model="ccEditorFcComparator" 
      ng-options="fcEnumComp for fcEnumComp in ccEditorDefaultComparators" 
      > 
    </select> 
    </div> 

的JS:

var app = angular.module('myApp', []); 

app.controller('myCtrl', function($scope) { 
    $scope.ccEditorDefaultComparators = ["=","!="]; 
    $scope.ccEditorFcComparator = "!="; 

    $scope.openPopup = function() 
    { 
    $('#mypopup').popup(); 
    $('#mypopup').popup('open', { y: 0 }); 

    console.log("should switch to = now"); 
     $scope.ccEditorFcComparator = "="; 

     //this makes it work the second time you open the popup 
    $('#fcComparator').selectmenu('refresh'); 
    } 
}); 
+2

通過檢查'select'我看到在標記中具有兩個選項「選擇= 「選擇」 – deblocker

回答

1

如果您selectmenu更改使用jQuery函數(.option())選擇的價值,它正確地更新選擇框。

伍重複的解決方案:

JSFiddle Demo

吳選項解決方案:

JSFiddle Demo

注:您需要separetely分配NG-模型變量也爲此修復工作。

JS:

var app = angular.module('myApp', []); 

app.controller('myCtrl', function($scope) { 
    $scope.ccEditorDefaultComparators = ["=","!="]; 
    $scope.ccEditorFcComparator = "!="; 

    $scope.openPopup = function() 
    { 
    $('#fcComparator').selectmenu('refresh'); 
    $('#mypopup').popup(); 
    $('#mypopup').popup('open', { y: 0 }); 
    console.log("should switch to = now"); 
     $('#fcComparator').val("="); 
     $scope.ccEditorFcComparator = "="; 
     //this makes it work the second time you open the popup 
    $('#fcComparator').selectmenu('refresh'); 
    } 
}); 

參考文獻:

  1. JQuery Select Menu Documentation
+0

你的小提琴不起作用,彈出窗口顯示「!=「not」=「 – AKMorris

+0

@AKMorris更新我的答案,請檢查:) –

+1

雖然這是一個答案,但它仍然沒用,我需要使用angularJs ng選項(根據我的原始代碼)來填充選擇框這意味着我不能硬編碼

0

難道是剛剛創建另一個控制器彈出和所選擇的選項有設置一個選項?

HTML

<div data-ng-app='myApp' data-ng-controller='myCtrl'> 

    <button id="popup-btn" ng-click="openPopup()">open popup</button> 

    <div data-role="popup" id="mypopup" data-overlay-theme="d" data-theme="none" ng-controller="myPopup"> 
    <select id="fcComparator" 
     ng-model="ccEditorFcComparator" 
     ng-options="fcEnumComp for fcEnumComp in ccEditorDefaultComparators"> 
    </select> 
    </div> 

</div> 

的Javascript

var app = angular.module('myApp', []); 

app.controller('myCtrl', function($scope, $timeout) { 
    $scope.openPopup = function() { 
    $('#mypopup').popup(); 
    $('#mypopup').popup('open', { y: 0 }); 
    } 
}); 

app.controller('myPopup', function($scope, $timeout) { 
    $scope.ccEditorDefaultComparators = ["=","!="]; 
    $scope.ccEditorFcComparator = "="; 
}); 

https://jsfiddle.net/wjjafupf/

+0

我需要將模型設置爲初始條件ion($ scope.ccEditorFcComparator =「!=」;)然後在彈出窗口中設置爲「=」。 – AKMorris

+0

此解決方案是否使用工廠或服務將「!=」的ccEditorFcComparator初始值從「myCtrl」控制器傳送/傳送到第二個「myPopup」控制器?基本上,我需要根據'myCtrl'中設置的初始值確定彈出選擇框的值,例如如果初始值爲「!=」,則將彈出窗口設置爲「=」。 – AKMorris

相關問題