extjs 5 : 为组件的自定义属性进行数据绑定 [英] extjs 5 : make a data binding for component's custom property

查看:26
本文介绍了extjs 5 : 为组件的自定义属性进行数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从文件域扩展的组件,我向它添加了一个自定义属性serverPath",并且我还定义了 getter 和 setter.

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 .

代码:

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'
    }
});

我不会粘贴 myViewModel 的定义.很简单.

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

结果绑定不生效.

有人可以帮忙吗?

推荐答案

你的班级应该是:

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

你应该已经准备好了,因为 ExtJS 会为你和 setter 创建 setter 和 getter.在你的视图模型中确保你有一个:

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'
}

已编辑遗漏了两件事:

  1. 当 ViewModel 上的值发生更改时,调度程序会异步发布更改.如果您希望立即反映更改,您需要在 ViewModel 上使用通知或在更改后延迟逻辑.
  2. 要获取类的自定义配置属性以将更改通知回 ViewModel,您需要将它们添加到发布"配置属性中.请参阅此更新的小提琴.

这篇关于extjs 5 : 为组件的自定义属性进行数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆