0

我想动态设置字段集标题。我有一个包含 1 个或多个字段集的表单。我希望字段集标题按 3 中的 1、3 中的 2 和 3 中的 3 顺序编号。例如,这是表单控制器中的一些代码:

var formView = this.getFormView(),
fieldsets = formView.down('fieldset');

for (var i = 0, len = fieldsets.length; i < len; i++) {
    fieldsets[i].setTitle((i + 1) + ' of ' + len)
}

我正在考虑获取表单面板 formView.getItems() 的项目并以这种方式查找字段集,但我确信有一种更简单的方法来获取字段集,然后动态设置它们的标题。

4

1 回答 1

0

我已经解决了你的问题。由于您没有给出“View.js”的编码,所以我创建了自己的视图 - “demo.js”。

 Ext.define("Stackoverflow.view.Demo", {
 extend: "Ext.form.Panel",
 config: {
    scrollable: 'vertical',
    items: [
        {
            xtype: "toolbar",
            docked: "top",
            title: "Set Title Dynamically ",
            items: [
                {
                    xtype: "button",
                    ui: "action",
                    text: "Set Title",
                    itemId: "settitle"
                }
            ]
        },

        { xtype: "fieldset",
          id: 'field1',
          title: 'oldtitle',
            items: [
                {
                    xtype: 'textfield',
                    name: 'name',
                    label: 'Name'
                }

            ]
        }

    ],
    listeners: [
        {
            delegate: "#settitle",
            event: "tap",
            fn: "onSetTitle"
        },
    ]
},

onSetTitle: function () {
   console.log("title");
   var z=Ext.getCmp('field1');
   z.setTitle('newtitle');
}

});

可能这会对你有所帮助。
如有任何疑问,请随时询问。
再见。

于 2012-09-15T14:06:15.170 回答