如何绑定字段集值

How to bind fieldset value

本文关键字:字段 绑定 何绑定      更新时间:2023-09-26

由于某种奇怪的原因,我无法绑定属性设置为 true checkboxToggle字段集的值。因此,其配置如下所示:

xtype: "fieldset",
title: "Box",
checkboxName: "bounding_box",            
checkboxToggle: true,
bind: {
    collapsed: "{!rec.bounding_box}"
} // results in error message: TypeError: this[c._config.names.set] is not a function
// bind: "{!rec.bounding_box}" does not work either

因此,上面的代码不起作用。但是,相同的技术适用于简单的checkbox字段:

xtype: "checkbox",
fieldLabel: "Show label",                
name: "show_label",
bind: "{rec.show_label}"

这有什么问题,我该如何解决?

如果您在调试版本中运行,您将收到一条错误消息,指出它无法绑定,因为字段集上没有 setCollapsed 方法。您可以非常轻松地添加它:

Ext.define('AddSetCollapsed', {
    override: 'Ext.form.FieldSet',
    setCollapsed: function(collapsed) {
        if (collapsed) { 
            this.collapse();
        } else {
            this.expand();
        }
    }
});