$(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是一个来自控制器的变量,一个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
当我执行上面的javascript时,控制台说:
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未捕获的ReferenceError:Geblockt未定义
我不知道为什么。 “Geblockt”是该地图的键,类型字符串。该错误仅显示地图的键,而不显示值。任何想法,任何人?
以下是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);
});
答案 0 :(得分:0)
根据您的示例Geblockt
被视为未定义的变量,因此您收到错误。
用引号分配它然后它将被视为字符串:
key = "{!item}";