2014-03-31 35 views
0

我有一個Kendo UI組合框,裏面填充了項目列表。我有兩個按鈕,一個用於遞增,另一個用於減少組合框上的索引。按鈕具有與點擊事件相關的功能。增加/減少Kendo combobox上的選定索引

問題是組合框的索引(顯示的值未被更改)未被遞增或遞減。以下是我的方法:

function IncrementTraveler() { 
    var combobox = $("#comboTraveler").data("kendoComboBox"); 
    var selectedIndex = parseInt(combobox.select()); 
    alert(selectedIndex); // displays correct index 

    if (selectedIndex < combobox.dataSource.data().length) { 
     $('#comboTraveler').select(selectedIndex + 1); // nothing changes 
    } 
} 

function DecrementTraveler() { 
    var combobox = $("#comboTraveler").data("kendoComboBox"); 
    var selectedIndex = parseInt(combobox.select()); 
    alert(selectedIndex); // displays correct index 

    if (!(selectedIndex < 0)) { 
     $('#comboTraveler').select(selectedIndex - 1); // nothing changes 
    } 
} 

感謝您的幫助!

回答

1

我相信你的問題是,你正在調用.select()方法在jQuery元素$('#comboTraveler)而不是你的combobox變量,這是Kendo組合框對象。在你的if語句,試試這個來代替:

combobox.select(selectedIndex + 1); 

...然後當然selectedIndex - 1DecrementTraveler()方法。

+0

awesomeness,nate。謝謝你的解釋。我完全沒有想到這一點。 –

+0

沒問題!這就是我們在這裏。 –