Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

value as variable

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hello,

is it possible to use a value of a variable as a variablename?

if I pass values through setparam it's something like this:
test.setparam({'action': 'index'});
The action in MyGrid is set to 'index'.

Code:
MyGrid = Ext.extend(Ext.grid.GridPanel, {
  webroot	: null,
  module	: null,
  controller	: null,
  action	: null,

  setparam	: function(param) {
    for(key in param) {
      // here I want to set key = param[key];
    }
  }

visit my website at
 
If you want to create a new variable based on the value in another, this should work:

Code:
var someVar = 'wibble';
window[someVar] = 'a value';
alert(wibble); // should give 'a value';

But I suspect that isn't what you're trying to do - can you elaborate a bit more?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
that's what I'm trying to do...

But it's not working. Maybe 'cause I have to access the variable in my object with "this". If I want to set webroot I have to use this.webroot in the setparam. But using window[this.key] (or something) doesn't work.

Code:
test = new Mygrid;
test.setparam({'webroot':'[URL unfurl="true"]http://localhost'});[/URL]

MyGrid = Ext.extend(Ext.grid.GridPanel, {
  webroot   : null,
  setparam  : function(param) {
    for(key in param) {
      // the variable with the key has to become the value
      // in your example
      window[key] = param[key];
    }
  }
}

Anyway I solved the problem by using an array. But if you find the solution let me know.

Code:
MyGrid = Ext.extend(Ext.grid.GridPanel, {
  params    : new Array(),
  setparam  : function(param) {
    for(key in param) {
      this.params[key] = param[key];
    }
  }
}

visit my website at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top