0

当试图枚举数据对象的值时,它的所有属性的值都是未定义的,但是在不枚举的情况下获取值会给出字符串数据的值(工作)......

毫无问题地创建 jstree 节点...

 $("#treeFile1").jstree("create", null, "outside", { "attr" : { "rel" : "folder" }});

监听上面的事件

 $("#treeFile1").bind("create.jstree", function(event,data)
 {      
alert(data.args.toSource()); // gives a string output not defined
    alert(data.inst.toSource());

for(var prop in data)
{
     alert("Property name is: "+ prop + "  property value is: "+  data.prop);
         // gives each value as undefined, why is this?
}
     event.stopImmediatePropagation();
4

1 回答 1

4

因为您需要使用括号表示法而不是点表示法来使用prop'作为访问的属性名称:

alert("Property name is: "+ prop + "  property value is: "+  data[prop]);

MDN 的文档提供了一个可靠的for...in示例

于 2013-03-26T16:11:22.977 回答