2014-05-05 25 views
-1

我需要動態管理組合框(動態更改選項),但我無法重新初始化組合框。 在啓動時的組合充滿就緒功能$(文件)。就緒(函數():如何使用sparkbox的sbCustomSelect函數動態管理組合框

用於設置組合框選項的功能是sparkbox的sbCustomSelect() 當特定條件發生了,我需要的。清空組合框選項並添加新的選項,但在更改後會顯示兩個組合框:舊的組合框和所有的啓動選項,以及添加了新選項的新組合框。 任何想法?提前致謝....

+1

請張貼一些代碼 – jeugen

回答

0

index.html中:

<div class="title"> 
<h2 class="">SR Ref #<a href="javascript:" class="detailsSrRef"></a></h2> 
<select class="event detailsEvents" data-role="none" id="selEvent"> 
</select> 
</div> 

在的script.js存在處於就緒功能初始化:

$(document).ready(function() { 

..... 

var serviceRequestDetailsController = new .ServiceRequestDetailsController(); 
serviceRequestDetailsController.setEventControllers([ 
    new AcceptEventController(), 
    new RejectEventController(), 
    new TravelToMaterialEventController(), 
    new TravelToCustomerEventController(), 
    new ArrivedAtCustomerEventController(), 
    new ValidateOOSEventController(), 
    new CompleteActionPlanEventController(), 
    new ReturnPartsEventController(), 
    new AddTextEventController(), 
    new ExceptionEventController(), 
    new FixAcceptedEventController() 
]); 

..... 

} 

在action.js:

var html = '<option data-placeholder="true" >Select Event</option>'; 
    for (var idx = 0; idx < eventControllers.length; idx++) { 
     //Fix 
     if (!(eventControllers[idx].getEventName() == com.ibm.client.dto.ServiceRequest.TRAVEL_TO_MATERIALS_STATUS)) 
if (!(eventControllers[idx].getEventName() == com.ibm.client.dto.ServiceRequest.PARTS_RETURNED_STATUS)) 
if (!(eventControllers[idx].getEventName() == com.ibm.client.dto.ServiceRequest.FIX_ACCEPTED_STATUS)) 
html += '<option value="' + utility.htmlEncode(eventControllers[idx].getEventName()) + '">' + 
      utility.htmlEncode(eventControllers[idx].getEventName()) + '</option>' 
} 

$('.detailsEvents').each(function(){ 
$(this).html(html); 
$(this).change(function() { 
var value = $(this).find(":selected").val(); 
$(this).sbCustomSelect(); 
}); 

這些都是我的變化在action.js的功能添加一個新的選項:

if (logicalStatus=="TAK"){ 

$('#selEvent').empty(); 
var newOption=$('<option value="' + utility.htmlEncod (com.ibm.client.dto.ServiceRequest.ADD_TEXT_STATUS) + '">' + 
        utility.htmlEncode (com.ibm.client.dto.ServiceRequest.ADD_TEXT_STATUS) + '</option>');   
    $('#selEvent').append(newOption); 
} 

我希望這是明確的,因爲代碼不在一個文件中。