extjs6 classic - How to do Data binding in extjs 6 -


i have json this.

     firstname: 'xyz',      comments : [{         emailaddress : "abc@gmail.com", body : "pqr",         emailaddress : "xyz@gmail.com", body : "xyz",      }] 

i want show firstname in textfield editable. , want show comments in grid. not able understand how it. please me that.

my view following:

    ext.define("sampleview", {        extend: "ext.panel.panel",        alias: 'widget.sample',        id : 'samplevid',        requires: ['studentviewmodel'],        viewmodel: {              type: 'studentviewmodel'         },        layout: {             type: 'vbox',             align: 'stretch'        },    initcomponent: function() {     ext.apply(this, {         items: [this.form(), this.grid()],                });     this.callparent(arguments);  },  grid: function(){     return {         xtype: 'grid',         reference: 'samplegrid',         id : 'samplegridid',         bind: {             store: '{comment}'<-- not able binding         },         flex:1,         margin: 10,         plugins: {             ptype: 'rowediting',             clickstoedit: 2         },         columns: [{             text: 'email',             dataindex: 'email',             flex: 1,             editor: {                 allowblank: false             }         }, {             text: 'role',             dataindex: 'body',         }],         }     } },   form : function(){     return{         xtype : 'form',         items:[{             xtype: 'textfield',             fieldlabel: 'first name',             bind: {                 value: '{firstname}'<---- how bind valuw     textfield             }         }]     } }     

});

my view model this:

    ext.define('studentviewmodel', {        extend: 'ext.app.viewmodel',        alias:'viewmodel.studentviewmodel',        requires: [            'student'        ],        stores: {             orderstore: {               autoload:true,               type: 'samples'             }        }     }); 

my model this:

    ext.define('student', {        extend: 'ext.data.model',        idproperty: 'id',        schema: {            namespace: 'sample',            proxy: {               type:'ajax',               url: 'users.json',               reader:{                  type:'json',                  rootproperty:'data'              }          }      },     fields: [         { name: 'id', type: 'int' },         { name: 'firstname', type: 'string' },     ] }); 

your binding have based on record selected.

your model student needs defined have hasmany reference comments model proper store built bound, or have dynamically create store based on array data within model. suggest using relation, easier in long run.

where have binding of

value: {firstname} 

it should

value: {student.firstname} 

in view controller have bind student student model trying display in form using line looks

vm.setvalue('student', yourmodelobjecthere); 

if student model has proper has many relation comments, rest should okay.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -