1

hey guys so i'm trying to add a simple handler on a button in my window. The handler just sets a value from a text file to a combobox item id = 'wildanimal'

  items: [{
    itemId: 'button1',
    xtype: 'button',
    text: 'click the button',
         handler: function(){
                         Ext.Ajax.request({
            url: 'stuff.txt',
            method: 'GET',
            success: function (result){
            this.up('Ajax').down('wildAnimal').setValue(result.responseText)
                                                      }
                                         })
                                     }  

however I receive a Uncaught TypeError: Object [object global] has no method 'up' ... is there a way to do this without using .up ?

4

1 回答 1

0

这可能会解决您的问题。您的“this”引用是对 ajax 函数的引用,而不是对您期望的按钮的引用:

items: [{
    itemId: 'button1',
    xtype: 'button',
    text: 'click the button',
         handler: function(theButton){
            Ext.Ajax.request({
                url: 'stuff.txt',
                method: 'GET',
                success: function (result){
                    theButton.up('window').queryById('wildAnimal').setValue(result.responseText)
                }
            });
        }  
于 2013-07-12T22:02:47.297 回答