File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Need a little help with the map container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply locked New topic
Author

Need a little help with the map container

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Hi i have a function which is shown below



now the function receives parameters which will be different all the time , the problem i am having is with writing name values for example

is suppose to write the content of the variable columnName but instead it just writes down columnName even though its not in speech marks.
Javascript thinks that i am writing
var colDetail = {"columnName":record};
what should i do so that the value of columnName variable actually gets set as a name instead of the text "columnName"

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
In other words i want the key value to be a variable Name ..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Rajesh Khan wrote:is suppose to write the content of the variable columnName but instead it just writes down columnName even though its not in speech marks.

No it's not supposed to. JavaScript lets you leave off the quotation marks if the property key is an identifier*, but otherwise { abc: 1 } and { "abc": 1 } are completely equivalent. I'm not sure why you thought otherwise.

If you want to use a variable as a property key, you won't be able to use the object literal syntax to do so.

For example, if abc is a variable that contains "xyz" which is what you want to use as the property name, you'd need to do:

is equivalent to { "xyz": 1 }






* But JSON does not let you leave off the quotes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Oh okay thanks for pointing that out although that's new and a bit confusing.., one last thing how do we find out if we are suppose to use an identifier or when we could use a variable in other places in Javascript?? (hope that makes sense)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Not really. I'm not sure what else to say but that the name of a property in a string literal is itself literal.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

P.S. In JavaScript parlance it's usually called a hash rather than a map.
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Looks like i am having the same problem here



Notice the
document.createTextNode(rx)
rx is a variable and this wont work. I could simply move this function to the original text. But i really am looking for a rule or something so that I would know when passing variables are okay instead of the direct text.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Passing a variable to a function is always fine -- there is never a time where you need to pass a literal value versus a variable.

This is not the same issue at all. If it's not working, something completely different is at play.

Please start a new topic with more information on the problem. Perhaps an SSCCE would be of help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need a little help with the map container