访问 Javascript 中的属性

发布于 2024-10-22 00:51:29 字数 1486 浏览 0 评论 0原文

在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中二柚 2024-10-29 00:51:29

看一下这个更完整的 Playground 示例(您还可以在其中试验代码)。这是代码本身:

qx.Class.define("Foo", {
    extend: qx.core.Object,
    properties: {
      activeRow: {
        nullable : true,
        check: "Object"
      },
      activeRowInit: {
        nullable : true,
        check: "Object",
        init: {test1: null, test2: null}
      }
    },
    members : {
      setAndGet : function () {
        this.setActiveRow({a:1,b:2});
        /*this.setActiveRow(123);*/
        var x = this.getActiveRow();
        return x;
      },
      setAndGetMember : function () {
        this.setActiveRowInit({test1: 123, test2: 123 });
        var y = this.getActiveRowInit().test1;
        return y;
      }
    }
});
var f = new Foo();
alert(f.setAndGet());
alert(f.setAndGetMember());

它捕获您的代码片段,其中包含一个带有“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:

qx.Class.define("Foo", {
    extend: qx.core.Object,
    properties: {
      activeRow: {
        nullable : true,
        check: "Object"
      },
      activeRowInit: {
        nullable : true,
        check: "Object",
        init: {test1: null, test2: null}
      }
    },
    members : {
      setAndGet : function () {
        this.setActiveRow({a:1,b:2});
        /*this.setActiveRow(123);*/
        var x = this.getActiveRow();
        return x;
      },
      setAndGetMember : function () {
        this.setActiveRowInit({test1: 123, test2: 123 });
        var y = this.getActiveRowInit().test1;
        return y;
      }
    }
});
var f = new Foo();
alert(f.setAndGet());
alert(f.setAndGetMember());

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).

云醉月微眠 2024-10-29 00:51:29

如果第一个示例有效,则意味着 setActiveRow 方法需要一个整数作为其参数,因此传递关联数组 {test1: 123, test2: 123 } 可能会破坏它。

因此,请使用第一个示例中的代码:

this.setActiveRow(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:

this.setActiveRow(123);

Then the second line should work fine assuming test1 is property of the class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文