3.x版本的@property({visible:function() {return this.a}}) this的作用域不是组件

  • Creator 版本: 3.1.1

  • 目标平台: win7

  • 重现方式:@property({visible:function() {return this.a}}) this的作用域不是组件本身,尝试过visible() {return this.a}、visible:()=> {return this.a}都无效

解决了吗,我也遇到这个问题了

把This通过function传进去:

@ccclass("testDump")
export class testDump extends Component {
    @property({type: CCInteger})
    public testProp: CCInteger = 2;

    @property({type: Node, visible: function (this: testDump){ 
        return this.testProp > 0
    }})
    public testNode: Node = null;
}
2赞

可以了,感谢大大~

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。