获取RadComboBox客户端旧的选中项

时间:2015-11-12 08:33:38

标签: javascript jquery asp.net telerik radcombobox

我的页面上有一个可选择的telerik RadComboBox组件。我正在使用" OnClientDropDownClosed"客户端事件。我会手动回发,而不是自动回复。我想要的是,当下拉菜单关闭时,我想将旧的已检查项目与客户端上的新检查项目进行比较。如何通过javascript获取旧的已检查项目和新检查的项目?

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。我保留旧选择的IdList。在rad组合框关闭函数,我比较两个列表。

var oldSelectedIdList = [];

function radComboBoxSelectedIdList() {
            var selectedIdList = [];
            var combo = $find("<%= RadComboBox.ClientID %>");
            var items = combo.get_items();
            var checkedIndices = items._parent._checkedIndices;
            var checkedIndicesCount= checkedIndices.length;
        for (var itemIndex = 0; itemIndex < checkedIndicesCount; itemIndex++){
            var item = items.getItem(checkedIndices[itemIndex]);
            selectedIdList.push(item._properties._data.value);
        }
        return selectedIdList;
    }

    $(document).ready(function () {
        oldSelectedIdList = radComboBoxSelectedIdList();
    });

    function areThereAnyChangesAtTheSelection()
    {
        var selectedIdList = radComboBoxSelectedIdList();
        var isTheCountOfEachSelectionEqual = (selectedIdList.length == oldSelectedIdList.length);
        if(isTheCountOfEachSelectionEqual == false)
            return true;

        var oldIdListMINUSNewIdList = $(oldSelectedIdList).not(selectedIdList).get();
        var newIdListMINUSOldIdList= $(selectedIdList).not(oldSelectedIdList).get();

        if (oldIdListMINUSNewIdList.length != 0 || newIdListMINUSOldIdList.length != 0)
            return true;

        return false;
    }

    function onRadComboBoxClosed(sender, args) {
        if (areThereAnyChangesAtTheSelection())
             //Your Code Here
    }