2013-07-08 5 views
0

У меня есть окно ExtJS, содержащее в нем checkboxgroup s и кнопку для получения выбранных значений.Не удается получить значение checkboxgroup в окне extjs

enter image description here

У меня есть два isseus с ним. Это код:

Ext.create('widget.window', 
    { 
     title : 'Select which scenario to run', 
     draggable: true, 
     modal: true, 
     header : 
     { 
      titlePosition : 2, 
      titleAlign : 'center' 
     }, 
     closable : true, 
     closeAction : 'hide', 
     width  : 400, 
     height  : 350, 
     x   : contentPanel.getX() + 50, 
     y   : contentPanel.getY() + 50, 
     layout: { 
     type: 'hbox', 
     align: 'stretch' 
     }, 
     items: 
     [ 
      { 
       xtype: 'panel', 
       title: 'If success', 
       itemId : 'success', 
       autoScroll:true, 
       flex: 1, 
       items: 
       [{ 
        xtype: 'checkboxgroup', 
        columns: 1, 
        vertical:true, 
        items: 
        [ 
         { boxLabel: 'Item 1', name: 'rb', inputValue: '1' }, 
         { boxLabel: 'Item 2', name: 'rb', inputValue: '2' }, 
         { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }, 
         { boxLabel: 'Item 4', name: 'rb', inputValue: '4' }, 
         { boxLabel: 'Item 2', name: 'rb', inputValue: '2' }, 
         { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }, 
         { boxLabel: 'Item 4', name: 'rb', inputValue: '4' }, 
         { boxLabel: 'Item 5', name: 'rb', inputValue: '5' }, 
         { boxLabel: 'Item 6', name: 'rb', inputValue: '6' } 
        ] 
       }] 
      }, 
      { 
       xtype: 'panel', 
       title: 'If failure', 
       id: 'failure', 
       autoScroll:true, 
       flex: 1, 
       items: 
       [{ 
        xtype: 'checkboxgroup', 
        columns: 1, 
        vertical:true, 
        items: 
        [ 
         { boxLabel: 'Item 1', name: 'rb', inputValue: '1' }, 
         { boxLabel: 'Item 2', name: 'rb', inputValue: '2' }, 
         { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }, 
         { boxLabel: 'Item 4', name: 'rb', inputValue: '4' }, 
         { boxLabel: 'Item 2', name: 'rb', inputValue: '2' }, 
         { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }, 
         { boxLabel: 'Item 4', name: 'rb', inputValue: '4' }, 
         { boxLabel: 'Item 5', name: 'rb', inputValue: '5' }, 
         { boxLabel: 'Item 6', name: 'rb', inputValue: '6' } 
        ] 
       }] 
      } 
     ], 
     buttons: 
     [{ 
      text : 'Save', 
      itemId : 'if_save', 
      icon : '../images/save.png', 
      ui  : 'default', 
      handler : function() 
      { 
       var cb_f = Ext.getCmp('failure').getValue() 
       alert(JSON.stringify(cb_f)); 
      } 
     }] 

    }).show(); 

В обработчике кнопок я хочу получить выбранные элементы из флажков.
Я пробовал this.getComponent('success').getValue(), Ext.getCmp('failure').getValue(), но firebug продолжает говорить, что они не определены.

Итак, Как я могу получить значения на «Сохранить»?

Благодаря

ответ

0

это должно работать:

listeners: 
{ 
    change: function(field, newValue, oldValue, eOpts) 
    { 
     console.log(newValue.rb); 
    } 
} 
+0

спасибо это работает – Brian

1

в соответствии с: Getting all selected checkboxes in an array , я хотел бы предложить что-то вроде этого:

расширить свой checkboxgroup с Id:

[{ 
    xtype: 'checkboxgroup', 
    id: 'myGroup', 
    columns: 1, 
    vertical: true, 
    items: 
    [ 
     { boxLabel: 'Item 1', name: 'rb', inputValue: '1' }, 
     { boxLabel: 'Item 2', name: 'rb', inputValue: '2' }, 
     { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }, 
     { boxLabel: 'Item 4', name: 'rb', inputValue: '4' }, 
     { boxLabel: 'Item 2', name: 'rb', inputValue: '2' }, 
     { boxLabel: 'Item 3', name: 'rb', inputValue: '3' }, 
     { boxLabel: 'Item 4', name: 'rb', inputValue: '4' }, 
     { boxLabel: 'Item 5', name: 'rb', inputValue: '5' }, 
     { boxLabel: 'Item 6', name: 'rb', inputValue: '6' } 
    ] 
}] 

, так что y позже вы можете получить выбранные товары через селектор:

buttons: 
[{ 
    text: 'Save', 
    itemId: 'if_save', 
    icon: '../images/save.png', 
    ui: 'default', 
    handler: function() { 
     var group = Ext.getCmp('myGroup'); 
     var checkedArray = group.query('[checked="true"]'); 

     var cb_f = Ext.getCmp('failure').getValue(); 
     alert(JSON.stringify(cb_f)); 
    } 
}] 

надеюсь, этот ответ тоже помогает!

0

Попробуйте следующее:

buttons: 
    [{ 
     text : 'Save', 
     itemId : 'if_save', 
     icon : '../images/save.png', 
     ui  : 'default', 
     handler : function() 
     { 
      var cb_f = Ext.getCmp('failure').getValue()["rb"]; 
      alert(cb_f); 
     } 
    }] 
3

Если создать идентификатор для checkboxgroup, например,

xtype: 'checkboxgroup', 
id: 'SUCCESS_CHECKBOX_ID', 
columns: 1, 
vertical:true, 
items: 
[ 
    { boxLabel: 'Item 1', name: 'rb', inputValue: '1' }, 
    { boxLabel: 'Item 2', name: 'rb', inputValue: '2' }, 
    { boxLabel: 'Item 3', name: 'rb', inputValue: '3' } 
] 

Вы можете сделать следующее:

handler : function() 
{ 
    var selectedSuccessValues = Ext.getCmp('SUCCESS_CHECKBOX_ID').getChecked();    
    for(var i=0;i<selectedSuccessValues.length;i++) 
    { 
    alert(selectedSuccessValues[i].inputValue); 
    }    
} 
Смежные вопросы