0

我们不喜欢在选定的项目中再次添加三个单词。我们喜欢验证拖放事件,并且需要显示您已经添加此记录的消息。
我尝试使用以下代码,但无法对相关事件进行验证

listeners: {
            added:function(obj,event){  
                  console.log("added");  
             },change:function(obj,event){  
                  console.log("change");  
             },removed:function(obj,event){  
                  console.log("removed");  
             }, blur:function(obj,event){  
                  console.log("blur");  
             }, click: function( obj) {  
                  console.log('click');   
             }, select: function( obj) {  
                   console.log('select');   
             }  
   }

请参阅下面的附图。

在此处输入图像描述

我正在使用 Extjs 3.4

4

1 回答 1

0

The change event fires when an item is selected or deselected... But at this stage, you won't be able to prevent it anymore. So, apparently, your best move is to override the onAddBtnClick method:

{
    xtype: 'itemselector'

    // ... config

    ,onAddBtnClick: function() {
        var me = this,
            selected = me.getSelections(me.fromField.boundList),
            i, l, record;

        var toStore = this.toField.boundList.getStore(),
            idField = 'value', // or 'id', or whatever you want
            selectedIds = Ext.pluck(Ext.pluck(toStore.getRange(), 'data'), idField),
            accepted = [], rejected = [];

        for (i=0, l=selected.length; i<l; i++) {
            record = selected[i];
            if (selectedIds.indexOf(record.get(idField)) === -1) {
                accepted.push(record);
            } else {
                rejected.push(record);
            }
        }

        if (rejected.length) {
            // warning msg
        }

        me.moveRec(true, accepted);
        me.toField.boundList.getSelectionModel().select(accepted);
    }
}
于 2013-08-28T12:06:34.950 回答