简体   繁体   中英

How to set value for input 'textfield' with JavaScript

i have a method in my openDB.js logic class:

getUserByUsername: function(username) {
        return this.getUsers(username).then(function(users) {
            return users[ username ];
        });
    },

i'm getting there user with a lot of properties/values. i have a extjs input 'textfield' , and i want to get in 'value' of textfield some user information. i know that all follow parameters has values (it is codesnippet from openDB.js CreateUser function):

.addParameter("DEPARTMENT", user.department)
            .addParameter("FAX", user.fax)
            .addParameter("FIRSTNAME", user.firstName)
            .addParameter("FUNCTION", user["function"])
            .addParameter("LASTNAME", user.lastName)
            .addParameter("LOCATION", user.location)
            .addParameter("MAIL", user.mail)
            .addParameter("MOBILE", user.mobile)
            .addParameter("PASSWORD", user.password)

i know it because its possible to check it with setTitle like this:

 openDB.getUserByUsername(user.username).then(function(userDetails)
        {
            debugger;
            me.setTitle("Welcome " + userDetails.department + "!");
        });

its works fine with all properties. but how to do it with 'textfield' value ????

 items: [{
                        xtype: "form",
                        bodyPadding: 5,
                        border: false,
                        defaults: {
                            xtype: "textfield",
                            inputType: "text",
                            anchor: "100%"
                        },
                        items: [{
                            fieldLabel: 'Firstname:',
                            id: 'firstName',
                            readOnly: true,
                            value: user.firstName,
                            name: "username"
                        }, {
                            fieldLabel: 'E-Mail:',
                            id: 'email',
                            value: 'user.email',
                            name: "email"
                        }, {

Use the getValue method on the field.

var f = new Ext.form.field.Text({
    renderTo: document.body,
    value: 'foo'
});
console.log(f.getValue());

after couple hours of Fitign with that -> BEST SOLUTION EVER:

items: [{
                        fieldLabel: 'Firstname:',
                        id: 'firstName',
                        readOnly: true,
                        value: user.firstName,
                        name: "username"
}]
... 
var name = Ext.getCmp('firstName').setValue('JohnRambo');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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