简体   繁体   English

动态更新无线电输入值(EXT JS 4.2.1)

[英]Dynamically Update Radio inputValue (EXT JS 4.2.1)

I am creating a radiogroup and when it's created, I set the "inputValue" to set the value of the field. 我正在创建一个无线电组,当创建它时,我设置“ inputValue”来设置字段的值。 For the first radio button, inputValue is set to 'I' (for in) and 'O' (for out) is set for the second radio button. 对于第一个单选按钮,将inputValue设置为“ I”(用于输入),将第二个单选按钮设置为“ O”(用于输出)。

If someone clicks the "OUT" radio, then a window pops up and asks them to choose a value from a combo box. 如果有人单击“ OUT”单选按钮,则会弹出一个窗口,要求他们从组合框中选择一个值。 The possible values there are 'F', 'R' or 'T' and if they select one of those, I'd like to modify the 'OUT' inputValue to reflect that. 可能的值有'F','R'或'T',如果他们选择其中之一,我想修改'OUT'inputValue以反映出来。 So when the form is submitted, it should, for example, send back 'F' instead of 'O'. 因此,提交表单时,例如,应发送回“ F”而不是“ O”。

Here is the code for the radio buttons: 这是单选按钮的代码:

items: [
    {
        xtype: 'container',
        defaultType: 'radiofield',
        allowBlank: false,
        blankText: 'Required',
        hideLabel: true,
        layout: 'hbox',
        items: [
            {
                xtype: 'radiofield',
                boxLabel: 'IN',
                name: 'susceptible_populations_1',
                width: 50,
                padding: '2 0 0 10',
                checked: true,
                inputValue: 'I',
                id: 'susceptible_populations_1_in'
            },
            {
                xtype: 'radiofield',
                boxLabel: 'OUT',
                name: 'susceptible_populations_1',
                width: 115,
                padding: '2 0 0 10',
                inputValue: 'O',
                id: 'susceptible_populations_1_out',
                listeners: {
                    click: {
                        element: 'el',
                        fn: function() {
                            show_popup_window('susceptible_populations_1_out', '9A(5)');
                        }
                    }
                }
            }
        ]
    }
]

I have Googled around and found a couple of solutions, but none of them seem to work for me. 我在Google周围搜索,找到了两个解决方案,但是似乎没有一个适合我。 All of them still return 'O' when I submit the form. 当我提交表格时,所有这些人仍然返回“ O”。

Here are some definitions for my popup window: 这是我的弹出窗口的一些定义:

  • FIELD_NAME is passed as the first parameter to the function. FIELD_NAME作为第一个参数传递给函数。 In this instance it is 'susceptible_populations_1_out' 在这种情况下,它是“ susceptible_populations_1_out”
  • TRUNCATED_FIELD_NAME is the same as above, except the '_out' has been removed. TRUNCATED_FIELD_NAME与上面的相同,除了已删除'_out'。 In this instance, it is 'susceptible_populations_1'. 在这种情况下,它是“ susceptible_populations_1”。 This is the name of the field that actually gets returned with my form post. 这是我的表单帖子实际返回的字段的名称。
  • record is the value of the combo box. record是组合框的值。 For this example, we can use the letter 'F'. 对于此示例,我们可以使用字母“ F”。

Here are some of the examples I am trying: 这是我尝试的一些示例:

Ext.getCmp(FIELD_NAME).setValue(record);

This appears to set the value of the radio to true. 这似乎将无线电的值设置为true。 The value should have already been set to true when I clicked on it, so this is redundant and doesn't change the inputValue to 'F' 当我单击该值时,该值应该已经设置为true,因此这是多余的,并且不会将inputValue更改为“ F”

Ext.get(FIELD_NAME).set({inputValue:record});

This appears to do nothing that I can tell. 这似乎无能为力。 I'm guessing that it's because to set something, the set needs a current name AND value and just sets that instance to true when it makes a match. 我猜这是因为要进行设置,该set需要一个当前名称AND值,并在匹配时将该实例设置为true。 This is not what I'm attempting to do. 这不是我要尝试做的。

var temp = Ext.get(Ext.ComponentQuery.query('[name=' + TRUNCATED_FIELD_NAME + ']')).getValue().elements[1];
Ext.get(temp).set({value:record});

Here I am attempting to access the element directly and it doesn't seem to do anything either. 在这里,我尝试直接访问该元素,它似乎也没有执行任何操作。 I've tried many different combinations of the preceeding code snippets also, (including replacing FIELD_NAME with TRUNCATED_FIELD_NAME in the above examples), but the value of the radio always comes back as 'O'. 我也尝试了前面代码段的许多不同组合(包括在上面的示例中用TRUNCATED_FIELD_NAME替换FIELD_NAME),但是无线电的值始终返回为“ O”。

In Sencha Touch, there seems to be a setGroupValue , but I couldn't find that in the EXT JS 4 docs anywhere. 在Sencha Touch中,似乎有一个setGroupValue ,但是我在任何地方的EXT JS 4文档中都找不到。 (Although getGroupValue works as expected.) (尽管getGroupValue可以按预期工作。)

Can someone please give me some guidance on this? 有人可以给我一些指导吗?

Thanks so much! 非常感谢!

you can set the config property later at any time 您以后可以随时设置config属性

Ext.getCmp(FIELD_NAME).inputValue = 'F'

only notice that getCmp with static ids should not be used, instead use ComponentQuery and itemId. 仅注意不要使用带有静态ID的getCmp,而应使用ComponentQuery和itemId。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM