使用Extjs  创建了一个textarea,用来显示信息,然后还有一个文本输入框,
现在要求是,将文本框中输入的值,显示到textarea中,但是不能将上次输出的清除掉,
现在我的做法是  var SendCmd = new Ext.form.FormPanel({
aotoHeight : true,
baseCls : 'bottomback',
buttonAlign : 'center',
border : false,
bodyStyle : 'padding: 10px 10px 10px 20px;',
labelWidth : 2,
defaults : {
anchor : '95%',
allowBlank : false,
msgTarget : 'side'
},
items : [{
xtype : 'textarea',
id:'Result',
name : 'Result',
height : 200,
readOnly : true,
allowBlank : true
 }, {
  xtype : 'textfield',
emptyText : '请输入...',
name : "Task",
listeners : {'specialkey':function(_field,_e){
if (_e.getKey() == _e.ENTER){
    var str = Ext.getCmp('Task').getValue();
    Ext.getCmp('Result').setValue(str);
}
}}
 }]
});但是这样写,他会将上次输入的清除了,只有本次输入的。
我要的结果是:
第一次:adb
第二次:adb
       aaaaaaa
第三次:adb
        aaaaaaa
        eeeeee就是说,,前面输入的还在,,怎么搞啊?

解决方案 »

  1.   

    var SendCmd = new Ext.form.FormPanel({
                aotoHeight : true,
                baseCls : 'bottomback',
                buttonAlign : 'center',
                border : false,
                bodyStyle : 'padding: 10px 10px 10px 20px;',
                labelWidth : 2,
                defaults : {
                        anchor : '95%',
                        allowBlank : false,
                        msgTarget : 'side'
                },
                items : [{
                            xtype : 'textarea',
                            id:'Result',
                            name : 'Result',
                            height : 200,
                            readOnly : true,
                            allowBlank : true
                         }, {
                             xtype : 'textfield',
                            emptyText : '请输入...',
                            name : "Task",
                            listeners : {'specialkey':function(_field,_e){
                                if (_e.getKey() == _e.ENTER){
                                    var str += Ext.getCmp('Task').getValue();
                                    Ext.getCmp('Result').setValue(str);
                                }
                            }}
                         }]
            });
      

  2.   

    var SendCmd = new Ext.form.FormPanel({
                aotoHeight : true,
                baseCls : 'bottomback',
                buttonAlign : 'center',
                border : false,
                bodyStyle : 'padding: 10px 10px 10px 20px;',
                labelWidth : 2,
                defaults : {
                        anchor : '95%',
                        allowBlank : false,
                        msgTarget : 'side'
                },
                items : [{
                            xtype : 'textarea',
                            id:'Result',
                            name : 'Result',
                            height : 200,
                            readOnly : true,
                            allowBlank : true
                         }, {
                             xtype : 'textfield',
                            emptyText : '请输入...',
                            name : "Task",
                            listeners : {'specialkey':function(_field,_e){
                                if (_e.getKey() == _e.ENTER){
                                    var str = Ext.getCmp('Result').getValue()+Ext.getCmp('Task').getValue();
                                    Ext.getCmp('Result').setValue(str);
                                }
                            }}
                         }]
            });
      

  3.   

    这是一个赋值的问题,我这边没有调试过,楼主自己调试一下看看
    你既然想保留原先的值,那就先获取textarea原先的值,再加上现在输入的值
      

  4.   


    Ext.onReady(function(){
        var SendCmd = new Ext.FormPanel({
                    aotoHeight:true,
                    buttonAlign:'center',
                    border:false,
                    bodyStyle:'padding: 10px 10px 10px 20px;',
                    labelWidth :2,
                    defaults:{
                            anchor : '95%',
                            allowBlank : false,
                            msgTarget: 'side'
                    },
                    items:[{
                                xtype : 'textarea',
                                id:'Result',
                                name : 'Result',
                                height : 200,
                                readOnly : true,
                                allowBlank : true
                             }, {
                                 xtype:'textfield',
                                 emptyText : '请输入...',
                                 name:"Task",
                                 id:"Task",
                                 listeners:{'specialkey':function(_field,_e){
                                    if (_e.getKey() == _e.ENTER){
                                        var str = Ext.getCmp('Result').getValue()+'\r\n'+Ext.getCmp('Task').getValue();
                                        Ext.getCmp('Result').setValue(str);
                                    }
                                }}
                             }]
                });
        var win=new Ext.Window({
            layout:'fit',
                    title:"test",
            width:620,
            height:350,
            constrain: true,
            resizable:false,
            collapsible:true,
                    closable:true,
            items:SendCmd
        });
        win.show();
    });
      

  5.   

    OK。。这边已经好了。。谢谢了不过还有个问题,,如果添加的很多的话,每次设置值后,textarea总是显示到最开始出,,,有没有办法让让他默认显示到最后?
      

  6.   

    呵呵。。解决啦,,再加一个Ext.get('ResultCMd').dom.scrollTop = Ext.get('ResultCMd').dom.scrollHeight;