0

I'm I'm using ExtJS to create a formPanel dynamyc from database (string result from server to object extjs)

Ext.Ajax.request({
     async : false,
     method : 'POST',
     url : '/Devt/GetFormItemCustomization',
     params : {
        TableName : 'tabeltest',
        col : 1
    },
    success : function (response) {
        var results = Ext.decode(response.responseText);
        console.log(results );
        var form = Ext.create('Ext.form.Panel', {
            width : 300,
            bodyPadding : 10,
            renderTo : 'formCustDiv',
            name : "test",
            items : [results]
        });
    }
})

this response from server:

{
   fieldLabel:'Employee Id',
   xtype:'textfield',
   allowBlank:false,
},
{
   fieldLabel:'Nick Name',
   xtype:'textfield',
   allowBlank: false,
}

but this only create one object from last data. Object

{
   fieldLabel: "Nick Name", 
   xtype: "textfield", 
   allowBlank: false
 }

i want response from server decode become two object:

Object {fieldLabel: "Employee Id", xtype: "textfield", allowBlank: false}

Object {fieldLabel: "Nick Name", xtype: "textfield", allowBlank: false}

Any suggests?

1 Answer 1

1

Well, your server should always return valid JSON. Two objects, comma-separated, isn't valid JSON. (You can check with one of the many online JSON validators if you don't believe me.) Could your server possibly return an array of objects? Like this:

[
    {fieldLabel: "Employee Id", xtype: "textfield", allowBlank: false},
    {fieldLabel: "Nick Name", xtype: "textfield", allowBlank: false}
]

In that case, you could easily go ahead and create a form from these by removing the array around the results variable:

var form = Ext.create('Ext.form.Panel', {
        width : 300,
        bodyPadding : 10,
        renderTo : 'formCustDiv',
        name : "test",
        items : results
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.