0

我有一个 ExtJS Formpanel,并且我已经为单击表单(而不是表单的任何字段)编写了一个监听器,它工作正常。

  1. 即使在将 Ext.FocusManager.Enable() 设置为 true 之后,我也无法让“模糊”正常工作。我错过了什么?

  2. 我无法从表单面板单击事件的事件处理程序访问表单字段。当我这样做时 - this.up.('form').get.(fieldname).value [在表单字段的事件处理程序中工作正常。]它说元素未定义。如何在此处访问表单元素?

添加代码片段 -

// Call it Object A     
Ext.create.('Ext.form.Panel', {

       id : xyz,


       items: [
       {
          xtype : 'textfield',
          name : 'test',
          fieldLabel : 'Name'
    }

    listeners : { // listener on the formPanel; not on any of its element
      click : {
            console.log("this works" );
     },
     focus : {
            console.log('this does not work');
    }

    }
    ]


    }

我这样做是为了可以访问另一个对象的值,比如 B.field。

Onload 我能够获取 B.field 的值。但是当用户更改不同选项卡上的 B.field 的值时,我无法获取 A 中 B.field 的更改值。我只是想办法避免 Ajax 调用数据库,如果可能的话.

在此先感谢您的时间。

4

1 回答 1

0

如果您的代码中没有任何示例可供参考,则很难确定您要做什么。

可能您只需要修复查询表单元素的方式。例如,工具栏中的元素不是表单的子元素,因此 up/down 不起作用。

我认为您不能在表单上监听事件focus、、blurclick。即使可以,我也不确定您是否愿意。focus相反,在字段或click按钮上侦听更为常见。

示例 1 带有字段使用focus和按钮使用的表单click

http://codepen.io/anon/pen/qEPRge?editors=001

;(function(Ext) {
  Ext.onReady(function() {
    console.log("Ext.onReady")

    var form = new Ext.create("Ext.form.Panel", {
      title: "person"
      ,items: [
        {itemId: "fld-id", fieldLabel: "id", name: "id", value: "1", xtype: "textfield", labelAlign: "top", labelSeparator: ""}
        ,{itemId: "fld-name", fieldLabel: "name", name: "name", value: "Emily", xtype: "textfield", labelAlign: "top", labelSeparator: ""}
        ,{itemId: "btn-submit", text: "submit", xtype: "button"}
      ]
    })
    form.on("afterrender", function(component) {
      console.log("form.afterrender")
    })
    form.render(Ext.getBody())

    form.queryById("fld-id").on("focus", function(component) {
      console.log("fld-id.focus")
    })

    form.queryById("fld-name").on("focus", function(component) {
      console.log("fld-name.focus")
    })

    form.queryById("btn-submit").on("click", function(component) {
      console.log("btn-submit.click")
      console.log("fld-id.value:")
      console.log(component.up("form").queryById("fld-id").getValue())
      console.log("fld-name.value:")
      console.log(component.up("form").queryById("fld-name").getValue())
    })
  })
})(Ext)
于 2015-02-02T17:38:50.890 回答