2017-05-25 71 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

是你的问题解决? –