extjs 5 : make a data binding for component's custom property
Asked Answered
C

1

6

i have a component that extended from the filefield, and i added a custom property 'serverPath' to it ,and also i have defined the getter and setter .

code :

Ext.define('MyApp.ux.Field.File',{
    extend:'Ext.form.field.File',
    xtype:'myfilefield',
    serverPath:'',
    getServerPath:function(){
    return this.serverPath;
},
setServerPath:function(serverPath){
    this.serverPath = serverPath;
}
});

Ext.create('MyApp.ux.Field.File',{
    bind:{
        serverPath:'{serverPath}'
    },
    viewModel:{
        type:'myViewModel'
    }
});

i will not paste the myViewModel's definition . it is simple.

and it turned out that the binding does not take effect.

can anyone help ?

Clawson answered 10/10, 2014 at 9:18 Comment(0)
H
8

Your class should be:

Ext.define('MyApp.ux.Field.File',{
  extend:'Ext.form.field.File',
  xtype:'myfilefield',
  config: {
    serverPath:''
  }   
});

And you should be all set because ExtJS will create the setter and getter for you as well as the setter. In your view model make sure you have a:

data: {
   serverPath : 'yourPathGoesHere'
}

Edited There are two things that were missing:

  1. When a value on the ViewModel changes the changes are asynchronously published by the scheduler. If you want the changes reflected immidiatly you need to use notify on the ViewModel or deffer the logic after the change a bit.
  2. To get custom config properties of a class to notify back the ViewModel of changes you need to add them in the 'publishes' config property. Please see this updated fiddle.
Hefty answered 4/12, 2014 at 1:5 Comment(7)
i have tried your suggestion , and sorry to found out that it did not work.Clawson
Hi, if you can provide some sort of JSFiddle/Sencha Fiddle it would be great so I can better recreate and possibly help with the issue.Hefty
hi , too much thx to you . the whole issue is here : github.com/happyyangyuan/Q-A/issues/1Clawson
great thanks!!! your 'lazy' and 'publishes' strategy is well done! i am a little disapointed on the sencha doc , they seldom mention the two config properties and the api doc has poor explanation on them either.Clawson
Glad it works. If the answer was correct please select it as the correct answer.Hefty
done! would you please see another question for me ? here :#27616710Clawson
Thanks again!You helped mu so much!Clawson

© 2022 - 2024 — McMap. All rights reserved.