$(document).ready(function() {
var key = "testkey";
var value = "testvalue";
<apex:repeat value="{!timeSpent}" var="item">
console.log(key);
console.log(value);
value = {!timeSpent[item]};
key = {!item};
console.log(key);
console.log(value);
</apex:repeat>
});
timeSpent is a variable coming from the controller, a Salesforce Map of String to Decimal:
public Map<String, Decimal> timeSpent = new Map<String, Decimal();
// the map gets values via further code which works fine
When I execute the above javascript, console says:
2015-04-01 12:29:11.354cmRP_ResourceDashboard:45 testkey 2015-04-01 12:29:11.354cmRP_ResourceDashboard:46 testvalue 2015-04-01 12:29:11.356cmRP_ResourceDashboard:49 Uncaught ReferenceError: Geblockt is not defined
And I have no idea why. "Geblockt" is a key from that map, type string. The error only shows up for the keys of the map, not for the values. Any ideas, anyone?
Here is the debug from the Inspector (chrome)
<script>
$(document).ready(function() {
var key = "testkey";
var value = "testvalue";
console.log(key);
console.log(value);
value = 0;
key = Geblockt; <---- HERE IS THE ERROR
console.log(key);
console.log(value);
console.log(key);
console.log(value);
value = 5;
key = PR-122;
console.log(key);
console.log(value);
});
As per your example Geblockt
be treated as variable which is not defined thus you are getting the error.
Assign It in quotes then it will be treated as string:
key = "{!item}";