简体   繁体   English

从对象中获取值,该对象是哈希图中的键

[英]Retrieve value from an Object which is a key in a hashmap

I have a DWR call which returns a MAP<Employee, Double>. 我有一个DWR调用,该调用返回MAP <Employee,Double>。 Employee is a class having attributes, employeeId and employeeName . Employee是一个具有employeeIdemployeeName属性的类。

In my javascript, I m doing something like this. 在我的JavaScript中,我正在做这样的事情。

for (var k in employees) {
    if (employees.hasOwnProperty(k)) {                  
        alert("EmployeeId : " + k.employeeId);
    }
}

It shows me undefined . 它告诉我undefined

key? 键? the k is the key. k是关键。 maybe you meant access the value of the key: 也许您的意思是访问密钥的值:

var employee = employees[k]

if employees[k] contains an object with the employeeId , then: 如果employees[k]包含一个具有employeeId的对象,则:

for (var k in employees) {
    if (employees.hasOwnProperty(k)) {                   
        alert("EmployeeId : " + employees[k].employeeId);
    }
}

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

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