Sunday 15 January 2012

javascript - Having trouble accessing Object element with a variable -


I have a different "session" that has been passed from a different function. I'm not sure how to format it so that I can use it as follows:

  function passed - // session = 'coverType_1') var tag = session.substring (Session.indexOf ("_") + 1); Document.write (dataBlock ['coverType _' + tag] ['coverage'] [1]);  

Displays this as "undefined" ...

As a comparison, though, it works:

  var i = 1; Document.write (dataBlock ['coverType _' + i] ['coverage'] [1]);  

How can I format "session" to use this object element as a variable?

I think the "session" has lost the scope of it from another function, it works within the previous function

Thanks in advance, it has thrown me for about a week. .

You can not find the correct tag , or data block < / Code> object.

var tag = session.substring (instead of session.indexOf ("_") + 1; , use the split () operator Next, I'm not sure if you want your to be session.plit ("_") [1];

DataBlock wants to be used as a 3-D array, but be careful if you have done so because you have a lot of data handling inside it. I use the console.log (dataBlock ['coverType _' + Tag]) first, then console.log (dataBlock ['coverType _' + tag] ['coverType _ '+ Tag]). To verify that you have the necessary data in it, if not, the "other function" that returns the data has been blocked.


No comments:

Post a Comment