我想在Ext JS 6.0.2組件中使用雙向綁定。然而,就我所能說的而言,這並不是我所期望的,或者完全不是。我創建了一個小例子:雙向綁定不更新視圖模型
Ext.define('MyComponentController', {
extend: 'Ext.app.ViewController',
alias: 'controller.mycomponent'
});
Ext.define('MyComponentModel', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.mycomponent'
});
Ext.define('MyComponent', {
extend: 'Ext.Component',
xtype: 'mycomponent',
viewModel: {
type: 'mycomponent'
},
controller: 'mycomponent',
config: {
thing: 'a defualt value'
},
bind: {
thing: '{thing}'
},
twoWayBindable: 'thing'
});
var myComponent = Ext.create('MyComponent', {
thing: 'a new value'
});
// Use setTimeout to give bindings time to update.
setTimeout(function() {
console.log(myComponent.getViewModel().get('thing'));
}, 1000);
我也有一個煎茶小提琴這裏:https://fiddle.sencha.com/#fiddle/1efk
我期望從運行此代碼是看a new value
登錄到控制檯。相反,我得到null
。即使設置了bind
和twoWayBindable
,我在視圖中設置的值也不會發布到我的視圖模型中。我誤解了如何使用雙向綁定?
這將工作,但它缺少重點。我試圖更新視圖模型中的東西的價值。你告訴我從視圖中獲取它,這在實際用例中不起作用。 –