当 child 组件在 extjs 中有 ViewModel 时如何将配置发布到 parent 组件
How to publish a config into parent component when the child component has ViewModel in extjs
我有一个 extjs class,它有一个 config 字段,现在我想 publish 它对 parent容器。
当我在 child 组件中没有 viewModel 时没问题,但是每当我将 viewModel 添加到 child class 时它就会中断!这是因为出版。它将其数据发布到最近的 ViewModel!
我怎样才能做到这一点?
检查 fiddle : https://fiddle.sencha.com/#fiddle/hj2
在 fiddle 中,如果您取消注释注释行,您将看到更改字段不会发布到 window header 中。
viewModel 默认为:{$value: null, lazy: true},传递“{}”配置可能是问题所在
viewModel:{$value: null}, //works
不幸的是我找不到完美的方法。我找到的唯一解决方案是:
1- 获取 child 的 ViewModel
2- 在 child 的 VM 上调用 bind 函数以获取更改并将值放入所需位置:
vm.bind('{a.c}',函数(v){w.setTitle(v)});
检查这个 fiddle : https://fiddle.sencha.com/#fiddle/hrp
从这里尝试 Bindable
覆盖
https://github.com/alexeysolonets/extjs-mvvm-extensions
为了您的问题,它是正确的。
我有一个 extjs class,它有一个 config 字段,现在我想 publish 它对 parent容器。
当我在 child 组件中没有 viewModel 时没问题,但是每当我将 viewModel 添加到 child class 时它就会中断!这是因为出版。它将其数据发布到最近的 ViewModel!
我怎样才能做到这一点? 检查 fiddle : https://fiddle.sencha.com/#fiddle/hj2 在 fiddle 中,如果您取消注释注释行,您将看到更改字段不会发布到 window header 中。
viewModel 默认为:{$value: null, lazy: true},传递“{}”配置可能是问题所在
viewModel:{$value: null}, //works
不幸的是我找不到完美的方法。我找到的唯一解决方案是: 1- 获取 child 的 ViewModel 2- 在 child 的 VM 上调用 bind 函数以获取更改并将值放入所需位置:
vm.bind('{a.c}',函数(v){w.setTitle(v)});
检查这个 fiddle : https://fiddle.sencha.com/#fiddle/hrp
从这里尝试 Bindable
覆盖
https://github.com/alexeysolonets/extjs-mvvm-extensions
为了您的问题,它是正确的。