Sencha touch:如何刷新输入标签

Sencha touch: How to refresh input label

本文关键字:刷新 输入 标签 touch 何刷新 Sencha      更新时间:2023-09-26

我有一个Ext.form.Select,我想在它的值变化时动态更新它的标签。虽然听起来很简单,但它拒绝工作:

var musicInCarInput = new Ext.form.Select({
    options: [
        {text: "Yes", value: "yes"},
        {text: "Maybe", value: "maybe"},
        {text: "No", value: "no"}
    ],
    name: "music",
    value: "maybe",
    label: '<img src="/static/images/comfort_icons/music_maybe_small.png" />',
    listeners: {
        change: function()
        {
            musicInCarInput.label = '<img src="/static/images/comfort_icons/music_'+musicInCarInput.getValue()+'_small.png" />';
        }
    }
});

我试图调用doLayout()后,我改变了标签,但我被告知,输入没有属性'布局',虽然记录了。

有什么想法吗?

这并不能直接回答问题,因为我没有发现如何更新标签,所以欢迎进一步的回答。我为我找到的解决方案是通过和id获取标签图像,并更新它。

如果其他人需要这个,下面是代码:

var musicInCarInput = new Ext.form.Select({
    options: [
        {text: "Yes", value: "yes"},
        {text: "Maybe", value: "maybe"},
        {text: "No", value: "no"}
    ],
    name: "music",
    value: "maybe",
    label: '<img id="music_input_label" src="/static/images/comfort_icons/music_maybe_small.png" />',
    listeners: {
        change: function()
        {
            el = Ext.getDom('music_input_label');
            el.setAttribute("src", '/static/images/comfort_icons/music_'+this.getValue()+'_small.png')
        }
    }
});

正确的答案来自SenchaTouch论坛上的realjax:有一个关于选择的属性(我很惭愧,我错过了)称为labelEl,它可以用来更新这样的包:

musicInCarInput.labelEl.setHTML([your hmtl stuff])