2016-06-13 58 views
0

如何將一個組合框的名稱(即顯示文本)綁定到某個其他組件?如何綁定到組合框顯示值?

我有一個名爲'combo'的組合框,我在其他地方的面板中有一個標籤,它使用組合顯示值更新自己。這兩個小部件通過ViewModel綁定。

如果我這樣設置綁定:

combo.setConfig({bind: {value: bindName}}; 

則標籤將顯示組合(即密鑰)的

如果我這樣做:

combo.setConfig({bind: {name: bindName}}; 

然後我收到此錯誤信息:

「無法在Ext.form.field.ComboBox綁定的名字 - 缺少的setName 方法」

我已經通過在組合框其他getter/setter方法沒有成功了,嘗試過:

combo.setConfig({綁定:{名稱:displayField}};

組合。調用setConfig({綁定:{名稱:rawValue}};

小提琴:https://fiddle.sencha.com/#fiddle/1bum

+0

的組合框的'name'不是顯示文本,但形式字段的名稱(如果名稱是'combo1',形式將值'value'作爲'combo1:value'提交,或將其存儲在名爲'combo1'的模型字段中。你試圖綁定到「顯示值」,它沒有屬性,也沒有配置選項來設置它。我擔心你必須手動進行綁定。你想達到什麼目的? – Alexander

+0

基本上我想綁定一個組合顯示/值對。我想在我的應用程序的其他位置顯示面板上的顯示文本。 –

+0

這裏是演示問題的小提琴:https://fiddle.sencha.com/#fiddle/1bum –

回答

2

添加一個參考到組合和結合於該選擇:

Ext.define('MyApp.view.TestView', { 
    extend: 'Ext.panel.Panel', 
    layout: 'form', 

    viewModel: { 
     type: 'test' // references alias "viewmodel.test" 
    }, 

    bind: { 
     title: 'Hello {name} {theCombo.selection.name}' 
    }, 

    items: [{ 
     xtype: 'textfield', 
     fieldLabel: 'first name', 
     bind: '{name}' 

    }, { 
     valueField: 'id', 
     displayField: 'name', 
     fieldLabel: 'last name', 
     reference: 'theCombo', 
     xtype: 'combo', 
     bind: '{combo}', 
     store: { 
      fields: ['id', 'name'], 
      data: [{ 
       "id": "1", 
       "name": "Jonston" 
      }, { 
       "id": "2", 
       "name": "Billson" 
      }, { 
       "id": "3", 
       "name": "Wayneston" 
      }] 
     } 
    }] 
}); 
+0

謝謝你這麼多! –