简体   繁体   English

Extjs:强制组件重新渲染

[英]Extjs: Force a component to re-render

I have a custom component in ExtJs that is a form field (GridField). 我在ExtJs中有一个自定义组件,它是一个表单字段(GridField)。 It displays a grid as a form field and works as expected. 它将网格显示为表单字段并按预期工作。 The observations are as follows: 观察结果如下:

  1. When the form is rendered alone (eg. in a window or the first panel in a card layout, everything shows just fine) 单独呈现表单时(例如,在窗口或卡片布局中的第一个面板中,一切都显示正常)

  2. When the form is is not the first panel in a card layout or is hidden the first time it is rendered, the field name shows and the space required is left but the control does not show. 如果表单不是卡片布局中的第一个面板或在第一次呈现时隐藏,则显示字段名称并保留所需的空间但控件不显示。

I did some inspection and found out that the custom component is actually rendered but the width of all the html elements (divs, etc) were 0. They all had the style (width:0). 我做了一些检查,发现实际渲染了自定义组件,但所有html元素(div等)的宽度都是0.它们都有样式(宽度:0)。 My guess is that it is because the form panel was not visible at the time the rendering was done. 我的猜测是因为表单面板在渲染完成时不可见。

In terms of implementation of the control, I am extending Ext.form.field.Base . 在控件的实现方面,我扩展了Ext.form.field.Base In initComponent , I simply call this.on('afterrender', this.initControl) to run the custom code for the additional control after render. initComponent ,我只需调用this.on('afterrender', this.initControl)来在渲染后运行附加控件的自定义代码。 Here the input field is hidden and the grid is rendered where it is supposed to be. 这里input字段被隐藏,网格呈现在它应该的位置。

My questions are 1. How do I force the control to re-render so that the width is no longer 0? 我的问题是1.如何强制控件重新渲染,使宽度不再为0? 2. If the current implementation is wrong, what is the right way to use a grid or another ext component as a form field? 2.如果当前实现错误,使用网格或其他ext组件作为表单字段的正确方法是什么?

Have you tried to call the "doLayout" method to make sure that the dimensions are reapplied correctly? 您是否尝试调用“doLayout”方法以确保正确重新应用维度? Re-rendering is not common in Extjs, usually doLayout does the trick. 重新渲染在Extjs中并不常见,通常doLayout可以解决问题。 If it doesn't, there may be something up with your implementation itself. 如果没有,那么您的实现本身可能会有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM