1

在使用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;

有谁知道语法的哪一部分是错误的?

先感谢您!

添加包含以下讨论:

警报(this.getActiveRow 的类型);返回:函数

警报(this.getActiveRow);

返回:

function(){
return qx.core.Property.executeOptimizedGetter(this, bI, name, "get");
}
4

2 回答 2

1

看看这个更完整的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',并获取整个属性,或者只是属性对象的成员。对我来说,这一切都按预期工作。如果您this.setActiveRow(123)在“setAndGet”方法中使用,您会收到一条合理的错误消息,例如“类型对象的预期值但得到 123”(在日志窗格中)。

于 2011-03-20T16:37:48.160 回答
0

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

所以有你在第一个示例中的代码:

this.setActiveRow(123);

然后第二行应该可以正常工作,假设test1是类的属性。

于 2011-03-14T15:33:34.090 回答