ExtJs4 Learning (fourteen) Form loading/updating Record (Model), extjs4record

Source: Internet
Author: User

ExtJs4 Learning (fourteen) Form loading/updating Record (Model), extjs4record

What is Record? A Record is a Record in a data Model object. Therefore, before using a Record, we need to define a Model.

Model Definition

For the definition of the Model, we will demonstrate it separately. Today it is only simple to use. The Model code is as follows:

Ext.define("UserModel", {    extend: 'Ext.data.Model',    fields: ["UserName", "Email"]});

After defining the Model, we can create a record:

var userRecord = Ext.create("UserModel", {    UserName: "Qi Fei",    Email: "youring2@gmail.com"});
Form load Record

The Form component provides the loadRecord () method to load Record objects.

var formCmp = this.up("form");formCmp.loadRecord(userRecord);
Form updates Record

When we edit the data in the Form and want to reflect the changed results to the Record, we need to use the updateRecord () method. The premise of using the updateRecord method is, our Form has called the loadRecord method to bind the Record data.

var formCmp = this.up("form");formCmp.updateRecord();console.log(userRecord);
Remove Record bound to Form

After the Form is bound to a Record, if we need to bind the basic Record, we can use the Reset method to pass in the true parameter. In this case, both the Form interface and the bound Record are cleared.

var formCmp = this.up("form");formCmp.getForm().reset(true);
Online example

The complete code for the entire demonstration is as follows:

Ext. onReady (function () {Ext. define ("UserModel", {extend: 'ext. data. model ', fields: ["UserName", "Email"]}); var userRecord = Ext. create ("UserModel", {UserName: "Qi Fei", Email: "youring2@gmail.com"}); Ext. create ("Ext. form. formPanel ", {title:" ExtJS Form loading/updating Record ", width: 350, height: 300, x: 30, y: 30, layout:" form ", bodyPadding: "5", defaultType: "textfield", fieldDefaults: {labelAlign: "right", labelWidth: 55}, items: [{name: "UserName", fieldLabel: "UserName ", allowBlank: false },{ name: "Email", fieldLabel: "Email"}], buttons: [{text: "loading Record", handler: function () {var formCmp = this. up ("form"); formCmp. loadRecord (userRecord) ;},{ text: "Update Record", handler: function () {var formCmp = this. up ("form"); formCmp. updateRecord (); console. log (userRecord) ;}}, {text: "reset", handler: function () {var formCmp = this. up ("form"); formCmp. getForm (). reset (true) ;}}], renderTo: "container "});});

Click to view Online Demo

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.