将局部变量传递给事件处理程序

时间:2011-02-23 17:54:04

标签: javascript extjs event-handling

h.d.d.w = Ext.extend(w.g.a,
{
    initComponent: function () {
      exampleFunctionA('Monday');
       //other fields omitted
    }
    exampleFunctionA: function (dayOfWeek) {
        this['WeekdayHoursStore' +dayOfWeek] = new Ext.data.Store({
            proxy: a.b.c.getProxy('d/e.asmx/f'),
            reader: g.h.i.j(
            [
              //array of config objects removed
            ]),
            sortInfo: //omitted
        });

        this['WeekdayHoursStore' +dayOfWeek].load(
        {
            params:
          {
              //parameters removed
          }
        });
        this['WeekdayHoursStore' +dayOfWeek].on("load", this._renderHours, this);
        //irrelevant code removed
    },

    _renderHours: function (dayOfWeek) {
        var dayIndex;
        for(var i = 0; i<7; i++){
            if(this.weekdays[i] === dayOfWeek){
                dayIndex = i;
                break;
            }
        }
        var record = this.WeekdayHoursStore.getAt(dayIndex);
        this['UseDefaultValue' +dayIndex] = record.get("UseDefault");
    }
    //further class members omitted
}

如何将dayOfWeek传递给_renderHours?

1 个答案:

答案 0 :(得分:4)

您可以创建一个匿名函数并从中调用this._renderHours

this['WeekdayHoursStore' +dayOfWeek].on("load", function() {
    this._renderHours(dayOfWeek);
}, this);