自定义函数内的变量

时间:2012-03-01 05:30:25

标签: extjs

我如何在Ext.Msg函数中访问下面的alRec变量,现在无法访问。

var alRec = allRecords[i];
prefFlag = true;

Ext.Msg.show({
    title:'Error',
    msg:"SOME MESSAGE",
    buttons: Ext.Msg.OKCANCEL,
    animEl: 'wId',
    icon: Ext.MessageBox.ERROR,
    fn: function(button,alRec) {
        if(button=='ok')
            this.onApply();
        else {
                        alRec.reject();
            return false;
        }
    }, 
    scope:this
});

1 个答案:

答案 0 :(得分:1)

var alRec = ['a'];
    Ext.Msg.show({
        title:'Error',
        alRec: alRec,
        msg:"SOME MESSAGE",
        buttons: Ext.Msg.OKCANCEL,
        animEl: 'wId',
        icon: Ext.MessageBox.ERROR,
        fn: function(button){
            console.log(this.alRec); //now its accesible
            if(button=='ok')
                this.onApply();
            else
            {
                //sth to do
                return false;
            }
        },
        scope:this
    });