Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need a little help with the map container

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
In other words i want the key value to be a variable Name ..
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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.
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
P.S. In JavaScript parlance it's usually called a hash rather than a map.
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic