如何调整Ext.field.TextArea的大小,使其与没有滚动条的文本大小完全相同



我在Sencha Touch 2应用程序中有一个Ext.field.TextArea。我只想根据它包含的文本在高度上展开。我该怎么做?这似乎是一个基本/简单的功能,但我在API中找不到它。

我正在使用这个组件来显示一些静态的多行文本——有没有其他组件更适合这个任务?

感谢您的帮助。

我是这样解决的:

Ext.define('ParentsApp.component.TextAreaAutomaticRow', {
extend: 'Ext.form.Select',
xtype: 'textareaautomaticrow',  
config: {
    maxRows: 2,
    autoHeight: true,
    listeners: {
        keyup: function (field, event) {
            if (field.autoHeight) {                 
                var numOfRows = field.getValue().split("n").length;
                if( numOfRows >= 2) {
                    numOfRows = numOfRows++;
                    field.setMaxRows( numOfRows );
                } else if (numOfRows < field.getMaxRows()) {
                    field.setMaxRows( numOfRows + 1 );
                }                   
            }
        }
    }       
},

});

对非表单项使用表单元素不是最佳解决方案。

我建议您考虑只使用一个轻量级的Ext.container.Container组件,或者如果您需要更高级的铬,可以使用Panel或Window。

最新更新