make it as object. string is not a valid data for that
Why is this argument not working?
-
06-10-2022 - |
Frage
I am trying to generate values dynamically and pass that to a function.
This is my code,
var color="{\"Hello\":\"#276040\"}";
alert(color); \\displays {"Hello":"#276040"}
sankey.setColors(color);
When I pass the color variable into that function it fails.
Instead of passing the argument, if I give the string directly it works.
sankey.setColors({"Hello":"#276040"}); //This works
What is the reason? How can I overcome that?
Lösung 3
Andere Tipps
Assuming the dynamic parts of your parameters are the key name and value, you could do something like:
var keyName = 'Hello';
var keyValue = '#276040';
sankey.setColors( { keyName: keyValue} );
var color contains a string in your code, Be careful for what sankey.setColors need. "{\"Hello\":\"#276040\"}" and {"Hello":"#276040"} isn't same values.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow