首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >addCls如何在ExtJS5中绑定ViewModel按钮

addCls如何在ExtJS5中绑定ViewModel按钮
EN

Stack Overflow用户
提问于 2015-06-13 16:27:40
回答 1查看 872关注 0票数 1

我想在绑定后更改css类。在ExtJS5中有可能吗?

我补充了一些评论。小提琴:https://fiddle.sencha.com/#fiddle/olc

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-13 18:44:21

您的代码中有几个问题:

  1. 无法绑定cls,因为没有setCls方法--如果需要,可以绑定iconCls。
  2. 不能在字符串(如iconCls:'{rating}'[0] )之后添加索引--这在语法上是不正确的。
  3. 如果像这样定义rating公式,就必须运行get函数- get()

试试这段代码

代码语言:javascript
复制
Ext.define('Fiddle.view.FooModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.fiddle-foo',

    data: {
        val: 1
    },

    formulas: {
        rating: function(get) {
            get();
            return 'hello-world';
        }
    }
});

Ext.define('Fiddle.view.Foo', {
    extend: 'Ext.panel.Panel',
    xtype: 'fiddle-foo',

    viewModel: {
        type:'fiddle-foo'
    },

    layout: 'hbox',
    height: 50,
    width: 250,
    items: [{
        xtype: 'button',
        text: 'rating 1',
        bind:{
         iconCls:'{rating}'
        }
    }, {
        xtype: 'button',
        text: 'rating 2',
        bind:{
         iconCls:'{rating}'
        }
    }, {
        xtype: 'button',
        text: 'rating 3',
        bind:{
         iconCls:'{rating}'
        }
    }]


});

Ext.application({
    name: 'Fiddle',

    launch: function() {
        new Fiddle.view.Foo({
            renderTo: document.body,
            width: 400,
            height: 400,
            title: 'Test'
        });
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30820939

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档