簡體   English   中英

ExtJs ComboBox 刷新選定(原始)值

[英]ExtJs ComboBox Refresh Selected (Raw) Value

我有一個帶有商店項目({值,文本})的 combobox,有時我需要更新文本。 當我這樣做時,所選值(文本)不會更新。

這是要說明的小提琴,代碼如下所示。 我們在下拉列表中選擇一個項目,然后單擊更新文本。 這將更新下拉列表中的文本,但不會更新 combobox 原始值。

[更新]:將 model.set() 替換為 store.loadData()

 Ext.application({ name: 'Fiddle', launch: function() { Ext.create("Ext.form.Panel", { renderTo: Ext.getBody(), width: 300, height: 200, bodyPadding: 20, layout: "form", items: [ { xtype: "combobox", itemId: "pickmin", fieldLabel: "Test", queryMode: "local", store: { fields: ["value", "text"], data: [ { value: 1, text: "Text 1" }, { value: 2, text: "Text 2" }, { value: 3, text: "Text 3" }, { value: 4, text: "Text 4" }, ] } } ], buttons: [ { text: "Update Text", handler: function (btn) { const combo = btn.up("form").down("#pickmin"); const newData = [] combo.store.each(r => { newData.push({ value: r.data.value, text: r.data.text + "0" }); }); combo.store.loadData(newData); } } ] }); } });

你必須使用

 r.set("text", r.data.text + "0");

更改每條記錄中的值。 您的按鈕代碼必須是:

 buttons: [{
            text: "Update Text",
            handler: function (btn) {
                const combo = btn.up("form").down("#pickmin");
                combo.store.each(r => {
                    r.set("text", r.data.text + "0"); 
                });
            }
          }]

更新

您可以使用該代碼解決它:

combo.getStore().on("load",
    function (store, records, successful, operation, eOpts) {
       combo.setValue(combo.getValue());
    },
    this
)

我已經為你寫了一個 Sencha fiddle 來展示解決方案: https://fiddle.sencha.com/#view/editor&fiddle/3cf6

如果有幫助,我很高興。 請考慮接受最佳答案。

您忘記為 combobox 設置 valueField 和 displayField 屬性 combobox 屬性應該是這樣的

 xtype: "combobox",
 itemId: "pickmin",
 valueField:"value",
 displayField :"text"

現在可以從 combobox 中獲取 rawValue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM