访问 Javascript 中的属性
在qooxdoo框架的使用中,在一个类中: (在 .xml 文件中 activeRow 被定义为 object_iterate: )
<object_literal name="activeRow" scope="static" constructor="false" deprecated="false" private="false" protected="false" ignored="true" internal="false" type="Object">
<property name="nullable" scope="static" constructor="false" deprecated="false" private="false" protected="false" ignored="true" internal="false" type="Boolean">
</property>
<property name="check" scope="static" constructor="false" deprecated="false" private="false" protected="false" ignored="true" internal="false" type="String">
</property>
</object_literal>
这确实有效:
properties: {
activeRow: {
nullable: true,
check: "Object"
},
...
this.setActiveRow(123);
var x = this.getActiveRow();
这不起作用:
properties: {
activeRow: {
nullable: true,
check: "Object",
init: {test1: null, test2: null}
},
...
this.setActiveRow({test1: 123, test2: 123 });
var y = this.getActiveRow().test1;
有谁知道语法的哪一部分是错误的?
先感谢您!
添加包含以下讨论:
alert(typeof this.getActiveRow);返回:函数
alert(this.getActiveRow);
返回:
function(){
return qx.core.Property.executeOptimizedGetter(this, bI, name, "get");
}
In use of the qooxdoo framework, in a class:
(in the .xml file activeRow is defined as an object_iterate: )
<object_literal name="activeRow" scope="static" constructor="false" deprecated="false" private="false" protected="false" ignored="true" internal="false" type="Object">
<property name="nullable" scope="static" constructor="false" deprecated="false" private="false" protected="false" ignored="true" internal="false" type="Boolean">
</property>
<property name="check" scope="static" constructor="false" deprecated="false" private="false" protected="false" ignored="true" internal="false" type="String">
</property>
</object_literal>
this DOES work:
properties: {
activeRow: {
nullable: true,
check: "Object"
},
...
this.setActiveRow(123);
var x = this.getActiveRow();
this DOES NOT work:
properties: {
activeRow: {
nullable: true,
check: "Object",
init: {test1: null, test2: null}
},
...
this.setActiveRow({test1: 123, test2: 123 });
var y = this.getActiveRow().test1;
Does anyone know which part of the syntax is wrong?
Thank you in advance!
Addition containing discussion below:
alert(typeof this.getActiveRow); returns: function
alert(this.getActiveRow);
returns:
function(){
return qx.core.Property.executeOptimizedGetter(this, bI, name, "get");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下这个更完整的 Playground 示例(您还可以在其中试验代码)。这是代码本身:
它捕获您的代码片段,其中包含一个带有“init”的属性和一个不带有“init”的属性,以及获取整个属性或仅获取属性对象的成员。对我来说,一切都按预期进行。如果您在“setAndGet”方法中使用
this.setActiveRow(123)
,您会收到一条合理的错误消息,内容类似于“类型对象的预期值,但得到了 123”(在日志窗格中)。Take a look at this more complete Playground example (where you can also experiment with the code). Here is the code itself:
It captures your code snippets, with a property with and one without 'init', and with getting the whole property, or just a member of the property's object. For me, it all works as expected. If you use
this.setActiveRow(123)
in the "setAndGet" method, you get a reasonable error message saying something like "expected value of type object but got 123" (in the log pane).如果第一个示例有效,则意味着
setActiveRow
方法需要一个整数作为其参数,因此传递关联数组{test1: 123, test2: 123 }
可能会破坏它。因此,请使用第一个示例中的代码:
然后假设
test1
是该类的属性,那么第二行应该可以正常工作。If the first sample works it means
setActiveRow
method is expecting an integer as its argument, so probably passing the associative array{test1: 123, test2: 123 }
is breaking it.So have such code as you have in the first sample:
Then the second line should work fine assuming
test1
is property of the class.