2017-05-25 83 views
11

我有一個tagfield,在其中加載一些值併發送到服務器。我想要的是再次重新加載該標記域組件時,應該自動選擇這些值。 目前他們不是自動選擇的,但是如果我將焦點放在標記字段上,那麼這些值就會隨着選擇而出現。如何在某些條件下自動聚焦tagfield

什麼是自動專注於某些條件的方法。並非所有的時間。

現在我只是顯示數據,但這不是正確的方法,在IE中這是行不通的。

我在這裏做什麼,目前

if(myField.xtype == "tagfield"){ 
     myField.xtype.setValue(myValue); 
     myField.xtype.inputEl.set({'placeholder':myValue}); 
    } 

我要的是

if(myField.xtype == "tagfield"){ 
     // Automatic Focus OR 
     // Someway by which I can set the value 
    } 
+0

你的意思是你正在經歷與[這個錯誤報告]一樣(https://www.sencha.com/forum/showthread.php?344610-Tagfield-with-createOnEnter-does-not-show-value-後loadRecord)? – Alexander

+0

@亞歷山大是一種類似的。當我點擊焦點時,我的價值越來越高。所以我只是想,無論如何,我可以專注於一旦我加載。此外,我使用我的代碼,但佔位符不在IE中工作。我檢查了文檔,並且有一個名爲'preFocus'的東西來避免使用'placeholder',但我不確定如何使用它。你能幫我怎麼用'preFocus'或類似的東西 – David

+0

我已經檢查過tagfield源代碼。請嘗試配置選項'autoLoadOnValue:true'是否適用於您。它從錯誤報告的小提琴中工作。 – Alexander

回答

1

我假設你tagfield配置對象是這個樣子。

var store = Ext.create('Ext.data.ArrayStore',{ 
fields: [ 
    'abbr', 
    'state', 
    'description', 
    'country' 
], 
data: [ 
    [0, 'AL', 'Alabama', 'The Heart of Dixie'], 
    [1, 'AK', 'Alaska', 'The Land of the Midnight Sun'], 
    [2, 'AZ', 'Arizona', 'The Grand Canyon State'], 
    [3, 'AR', 'Arkansas', 'The Natural State'], 
    [4, 'CA', 'California', 'The Golden State'], 
    [5, 'CO', 'Colorado', 'The Mountain State'], 
    [6, 'CT', 'Connecticut', 'The Constitution State'], 
    [7, 'DE', 'Delaware', 'The First State'], 
    [8, 'DC', 'District of Columbia', "The Nation's Capital"], 
    [9, 'FL', 'Florida', 'The Sunshine State'], 
    [10, 'GA', 'Georgia', 'The Peach State'], 
    [11, 'HI', 'Hawaii', 'The Aloha State'], 
    [12, 'ID', 'Idaho', 'Famous Potatoes'] 
] 
}); 

{ 
     xtype: 'tagfield', 
     fieldLabel: 'Select a state', 
     store: store, 
     reference: 'states', 
     displayField: 'state', 
     valueField: 'abbr', 
     filterPickList: true, 
     queryMode: 'local', 
} 

通過,如果你在標記字段選擇像Alabama,Alaska,Arizona狀態這樣的配置,那麼你會因爲在標籤字段配置得到這樣['AL','AK','AZ']值已設置valueField: 'abbr'和那些價值會到服務器進行保存。

重新加載後,如果你想選擇這些值,那麼你必須給出這三個值,因爲它是。像

if(myField.xtype == "tagfield"){//tagfield is in lower case 
     myField.setValue(['AL','AK','AZ']); // myField.setValue(myValue); 
} 

如果你仍然想集中同一領域,如果你正在裝載焦點tagfield的商店,那麼你可以使用標籤字段的focus方法。

if(myField.xtype == "tagfield"){ //tagfield is in lower case 
     myField.focus(true,true,function(){ 
     myField.getStore().load({ 
      callback: function(records, operation, success) { 
       myField.setValue(['AL','AK','AZ']);//myField.setValue(myValue);     
      } 
     }); 
    }); 
} 

希望這有助於。

如果您使用tagfield作爲widget,那麼您可以在widgetcolumn上使用onWidgetAttach配置,並且您可以在其上指定功能。

請參考link

+0

好的+1回答。但是,在這裏,我的'tagfield'是一個小部件列,只有在tagfield集中後纔會加載商店。那麼讓我試試你答案的第二部分。 – David

+0

請參閱我更新的答案。 –

+0

是你的問題解決? –