ExtJS:如何使用Single记录将标签绑定到ViewModel存储

hor*_*uzz 0 data-binding extjs viewmodel

请参阅以下小提琴:将商店从ViewModel绑定到xtype标签

我无法从我的ViewModel商店获取记录以显示在xtype: 'label'我的表单项中.

这应该很容易,但唉,我的大脑无法工作......

sce*_*i66 5

无法为商店的第一条记录创建绑定描述符.您需要为此目的实现一个公式.

在您的视图模型中:

formulas: {
    firstTestStoreRecord: {
        bind: '{testStore}',
        get: function(testStore) {
            return testStore.getAt(0);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在您的视图中使用它:

bind: {
    html: '<b>{firstTestStoreRecord.test}</b>'
}
Run Code Online (Sandbox Code Playgroud)

这是工作小提琴:https://fiddle.sencha.com/#fiddle/25cf&view/editor

  • @scebotari66“无法为商店的第一条记录创建绑定描述符”仅供参考,从 6.5 开始,这不再正确:https://fiddle.sencha.com/#fiddle/25ck&amp;view/editor (2认同)
  • 您可以绑定到first/last/count/totalCount。您还可以绑定到模型 dirty/phantom/valid,这是 6.5 中新添加的。 (2认同)