Jquery 为什么枚举对象会给出一个未定义的值?
当试图枚举数据对象的值时,其所有属性的值都为undefined,但在不枚举的情况下获取该值时,其值为string data(working)Jquery 为什么枚举对象会给出一个未定义的值?,jquery,jstree,Jquery,Jstree,当试图枚举数据对象的值时,其所有属性的值都为undefined,但在不枚举的情况下获取该值时,其值为string data(working) $("#treeFile1").bind("create.jstree", function(event,data) { alert(data.args.toSource()); // gives a string output not defined alert(data.inst.toSource()); for(var pr
$("#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();
创建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();
倾听上述事件
$("#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();
因为您需要使用而不是使用prop
的值作为访问的属性名称:
$("#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();
alert("Property name is: "+ prop + " property value is: "+ data[prop]);
MDN的文档提供了。,因为您需要使用而不是使用prop
的值作为访问的属性名称:
$("#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();
alert("Property name is: "+ prop + " property value is: "+ data[prop]);
MDN的文档提供了。+1;奇特的ES5方式:
Object.keys(data.forEach(function(p){alert(data[p])})
保存对对象可枚举属性的检查。确实如此,但当然,这在以前糟糕的IE版本中不受支持。没错,但IE9“已经”能够做到这一点。因此,它不会太远,因为我们可以使用这个没有问题;奇特的ES5方式:Object.keys(data.forEach(function(p){alert(data[p])})
保存对对象可枚举属性的检查。确实如此,但当然,这在以前糟糕的IE版本中不受支持。没错,但IE9“已经”能够做到这一点。因此,我们很快就能毫无问题地使用它。
$("#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();