Sencha touch:如何刷新输入标签

发布于 2024-11-04 20:55:11 字数 692 浏览 0 评论 0原文

我有一个 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() ,但我被告知输入没有属性“doLayout”,尽管有记录。

有人有什么想法吗?

I have an Ext.form.Select that I want to update it's label dynamically when it's value changes. Simple as it sounds, it refuses to work:

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" />';
        }
    }
});

I tried to call doLayout() after I change the label, but I'm told that the input has no property 'doLayout', although documented so.

Any ideas anyone ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捶死心动 2024-11-11 20:55:11

这并没有直接回答答案,因为我没有找到如何更新标签,所以欢迎进一步的答案。我找到的解决方案是通过 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')
        }
    }
});

This doesn't answer the answer directly, because I didn't found how to update the label, so further answers are welcomed. The solution that i found for me is to get the label image by and id, and update it.

If someone else needs this, here is the code:

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')
        }
    }
});
ぶ宁プ宁ぶ 2024-11-11 20:55:11

我从 SenchaTouch 论坛上的 realjax 得到了正确的答案:有一个select 上的属性(我很遗憾我错过了)称为 labelEl,它可用于更新包,如下所示:

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

The correct answer came to me from realjax on SenchaTouch forums: there is a property on the select (that I'm ashamed that I've missed) called labelEl, which can be used to update the bale like this:

musicInCarInput.labelEl.setHTML([your hmtl stuff]) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文