Results 1 to 4 of 4

Thread: Passing a local variable into an event handler

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    8

    Default Passing a local variable into an event handler

    Code:
    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
    }
    How can I pass dayOfWeek into _renderHours?

  2. #2
    Sencha User
    Join Date
    Dec 2010
    Posts
    139

    Default

    Edited: nvm, my idea was wrong
    Last edited by drian; 23 Feb 2011 at 11:16 AM. Reason: wrong code

  3. #3

    Default

    Call createDelegate on the argument that references _renderHours and tell it to make dayOfWeek the first argument by giving it a position of 0:

    Quote Originally Posted by Ppecher View Post
    Code:
    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.createDelegate(this, [dayOfWeek], 0), 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
    }
    How can I pass dayOfWeek into _renderHours?
    Johnathan Hebert

  4. #4
    Sencha User
    Join Date
    Feb 2011
    Posts
    8

    Default

    Thanks.

Similar Threads

  1. passing a few variable for each grid cell
    By nick saint in forum Ext 3.x: Help & Discussion
    Replies: 13
    Last Post: 23 May 2009, 6:58 AM
  2. from local to global variable
    By italoc in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 18 Feb 2008, 8:47 AM
  3. datagrid loaded with local variable
    By snod0g in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 11 Apr 2007, 1:33 PM
  4. passing variable to grid
    By noname in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 30 Mar 2007, 8:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •