简体   繁体   English

未捕获的参考错误: <mapkey> 没有定义

[英]Uncaught reference Error: <mapkey> is not defined

$(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: timeSpent是来自控制器的变量,它是String到Decimal的Salesforce映射:

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: 当我执行上述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 Uncaught ReferenceError: Geblockt is not defined 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

And I have no idea why. 而且我不知道为什么。 "Geblockt" is a key from that map, type string. “ Geblockt”是该映射中的键,键入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) 这是来自检查器(chrome)的调试

 <script>

$(document).ready(function() { $(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. 根据您的示例, Geblockt被视为未定义的变量,因此您将得到错误。

Assign It in quotes then it will be treated as string: 用引号将其分配,然后将其视为字符串:

key = "{!item}";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM