【问题标题】:Applying style to binding formula将样式应用于绑定公式
【发布时间】:2017-08-22 01:48:05
【问题描述】:

我正在尝试将样式应用于 ViewModel 中的绑定公式。

我的 ViewModel 是:

viewModel: {
                formulas: {
                    firstTestStoreRecord: {
                        bind: '{testStore}',
                        get: function(testStore) {
                            return testStore.getAt(0);
                        }
                    }
                },
                stores:{
                    testStore: {
                        //fields: [{ name: 'test', type: 'string' }],
                        data: [{
                            test: 'Foo',
                            style: {
                                'font-size': '22px',
                                'color':'red',
                            }
                        }]
                    }
                }
            },

我对绑定公式的参考是:

items: [{
                xtype: 'form',
                title: 'Bound form',
                flex: 1,
                items: [{
                    xtype: 'label',
                    bind: {
                        html: '<b>{firstTestStoreRecord.test}</b>',
                        bodyStyle: '{style}'
                    }
                }]
            }]

这是我正在尝试的小提琴:Bind store from a ViewModel to an xtype label with style。我正在尝试更改 html 中的字体样式,但它不起作用。我以此作为参考:How-to-bind-to-style-and-or-html-property

【问题讨论】:

  • 我看到的第一件事是你的html绑定到firstTestStoreRecord.test,但是你的样式NOT绑定到firstTestStoreRecord.style
  • 另外,标签没有bodyStyle,也没有style 配置。

标签: html extjs data-binding


【解决方案1】:

有两点不对:

  • 标签没有style,更不用说bodyStyle 配置了。如果要设置样式,则必须在标签上使用内联 HTML 或使用容器。
  • 您对样式的绑定不违反记录 (firstTestStoreRecord)。

更正和工作的代码:

items: [{
    xtype: 'container',
    bind: {
        html: '<b>{firstTestStoreRecord.test}</b>',
        style: '{firstTestStoreRecord.style}'
    }
}]

【讨论】:

  • 太棒了!谢谢!现在只需弄清楚如何在带有使用 AJAX 代理的模型的商店中使用它。
猜你喜欢
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
相关资源
最近更新 更多