面板的 setTitle() 函数不会发布到面板的视图模型

panel's setTitle() function does not publish to the panel's viewModel

本文关键字:模型 视图 函数 setTitle      更新时间:2023-09-26

当我调用extjs面板组件的setTitle函数时,标题会立即更新,但绑定到它的viewModel不会改变!

代码如下:

Ext.application({
    name: 'Fiddle',
    launch: function() {

        var textfield = Ext.create('Ext.form.field.Text', {
            itemId: 'textfieldItem',
            fieldLabel: 'fjdks',
            bind: '{customer.name}'
        });
        var panel = Ext.create('Ext.form.Panel', {
            viewModel: {},
            bind: {
                title: '{customer.name}'
            },
            renderTo: Ext.getBody(),
            items: [textfield]
        });
        panel.setTitle('123');
        Ext.Msg.alert('Fiddle', panel.getViewModel().get('customer.name'), function() {
            textfield.setValue('rrrrr');
            Ext.Msg.alert('Fiddle', panel.getViewModel().get('customer.name'));
        });
    }
});

见煎茶小提琴

这显然不是双向绑定。您可以将其作为错误或缺失的功能报告给Sencha,但是,通过扩展Ext.panel.Panel并实现applyTitle发布到viewmodel的方法很容易修复它。如果您决定采用这种方法,请不要忘记调用父应用标题。