开发者

ExtJS Textarea - autosave contents on user input

开发者 https://www.devze.com 2023-04-09 19:45 出处:网络
I\'m an ExtJS newbie and need to send the contents of a ExtJS Textarea to the backend server for saving (autosave facility) as the user types in. Is there a way to do it. I\'ve currently registered a

I'm an ExtJS newbie and need to send the contents of a ExtJS Textarea to the backend server for saving (autosave facility) as the user types in. Is there a way to do it. I've currently registered a keyup listener to collect the input value as shown below:

items: [{
    xtype: 'textarea',
    id: 'notes',
    anchor: '100%',
    height: 270,
    msgTarget: 'under',
    fieldLabel: 'Note',
    enableKeyEvents: true,
    listeners: {
        'keyup': function(textarea, event) {
         开发者_如何学编程   var v= textarea.getValue();
            Ext.Ajax.request({
                url: 'buffernote.action',
                params: {value: v}
            })
        }
    }
}
}]

Am I in the right direction?


If you need a buffer, put some ref to the textarea, then call

this.mon(myTextarea, 'keyup', this.onMyTextareaKeyup, this, {buffer: 1000});

where onMyTextareaKeyup contains the code that you provided to do the request. More info on buffer can be found on API.


You should use two events: one key event and one blur event (blur, change or valid) Then fill a 'key hit' buffer and write the whole field back if full and reset the buffer. Also write the whole field back if the blur event get executed.

Personally I am using stores that do the write & updates actions for me. So I just need to modify a record in the store. For that way you just need to play with record.beginEdit() & record.endEdit() In ExtJS 4.x they are now using the term Ext.data.Model but it behaves much the same as in ExtJS 3.x

The store will need the option autoSave: true otherwise you have to call save() on the store to submit any changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号