2012-03-02 33 views
0

我是一個使用Extjs 4.07的新手。我創建了一個組合框(遠程)queryMode。組合框顯示課程列表。然而,我最近工作的機構重新編寫了他們的整個課程。所以,我最終有兩個記錄具有相同的顯示字段。我的JSON如下所示:Extjs Comobobox重複顯示字段不允許設置?

{"result":[{"id":"90223","code":"CM12","description":"Introduction to C Programming","creditHours":"3.00","numberOfLabs":"0","contactHours":null,"chargeableCredits":null}, 
{"id":"2094","code":"CMPS1302","description":"Introduction to C Programming","creditHours":"3.00","numberOfLabs":"0","contactHours":null,"chargeableCredits":null}],"total":2} 

顯示字段是描述,值字段是id。當我選擇組合框中的其中一個項目並提交時,一切正常。如果稍後我選擇不正確的課程並選擇另一個,則會出現問題。

我曾嘗試設置idProperty:'id'但無濟於事。當我提交表格時,將發送的值是先選擇的值。注意:這隻發生重複的課程描述,其他一切正常。

這裏是一些代碼來幫助說明問題:

Ext.define('SIS.model.ManageCourse', { 
    extend: 'Ext.data.Model', 
    fields: [ 
     {name: 'id', type: 'int'}, 
     {name: 'code', type: 'string'}, 
     {name: 'description', type: 'string'}, 
     {name: 'creditHours', type: 'float'}, 
     {name: 'contactHours', type: 'float'}, 
     {name: 'chargeableCredits', type: 'float'}, 
     {name: 'numberOfLabs', type: 'float'}, 
     {name: 'selected', type: 'bool'} //for update course pre-requisites 
    ] 
}); 


Ext.define('SIS.store.ClassCourse', { 
    extend: 'Ext.data.Store', 
    autoLoad: true, 
    autoSync: true, 
    model: 'SIS.model.ManageCourse', 
    pageSize: 7, 
    remoteFilter: true, 
    idProperty: 'id', 
    proxy: { 
     type: 'ajax', 
     api: { 
      read: 'course/select' 
     }, 
     reader : { 
      type : 'json', 
      root : 'result', 
      totalProperty : 'total', 
      successProperty : 'success' 
     } 
    } 
}); 

Ext.define('SIS.view.class.ClassCourseCombo', { 
    extend: 'Ext.form.ComboBox', 
    alias: 'widget.ClassCourseCombo', 
    name: 'courseId', 
    fieldLabel: 'Course', 
    store: 'ClassCourse', 
    queryMode: 'remote', 
    pageSize: 7, 
    displayField: 'description', 
    valueField: 'id', 
    allowBlank: false, 
    hideTrigger: true, 
    forceSelection: true, 
    minChars: 1, 
    lazyInit: false, 
    listConfig: { 
     getInnerTpl: function() { 
      return '<div class="combo-header">{description}</div>\ 
       <div class="combo-item">{code}</div>'; 
     } 
    } 
}); 
+0

你能否用例子解釋你的問題「如果以後我選擇了不正確的過程並選擇另一個,就會出現問題。」令人困惑。 – Maggie 2012-03-02 01:08:35

+0

假設我想選擇Intro to C Programming(CM12),但是我錯誤地選擇了Intro to C Programming(CMPS1302)。即使我進行了更正,我的第一個選擇也會被提交。但是,如果我選擇其他課程,例如。軟件工程師,然後選擇Intro to C Programming(CMPS1302),這是可以接受的。 – winkie 2012-03-02 06:36:18

回答

0

這是自版本3以來發現的錯誤,我在Condor提供的sencha forum中找到了解決方案。

我改了行

if(val.length > 0 && val != this.emptyText) 

if(val.length > 0 && val != this.emptyText && typeof this.emptyText != 'undefined') 

當沒有emptyText定義的結果是一樣,如果forceSelection設置爲false,即使明確設置爲true。小修補程序。

0

具有在組合框中不同行相同的顯示值至少是混淆爲最終用戶。你爲什麼不創建一個計算字段這樣的:

fields: [ 
    { name: 'id', type: 'int' }, 
    { name: 'description', type: 'string' }, 
    { name: 'display', type: 'string', convert: function(v, r) { 
    return r.get('id') + ' ' + r.get('description'); 
    }} 
}] 

,並使用該display爲您displayField。

+0

我想過,但如果這樣做,那麼編輯組合時,將不會返回任何結果,因爲顯示字段用作查詢來從服務器獲取結果。我決定使用getInnerTpl來格式化顯示。 – winkie 2012-03-02 06:28:16

+0

這也可以... – sha 2012-03-02 11:29:51