如何在某些条件下自动对焦标记域

Dav*_*vid 11 javascript extjs extjs6

我有一个标记字段,我在其中加载一些值并发送到服务器.我想要的是再次重新加载那个标记字段组件时,应该自动选择这些值.当前它们不是自动选择的,但是如果我将焦点放在标记字段上,那么这些值将按选定的方式进行.

什么是自动关注某些条件的方法.不是所有的时间.

现在我只是显示数据,但这不是正确的方法,在IE中这是行不通的.

这就是我目前正在做的事情

if(myField.xtype == "tagfield"){
        myField.xtype.setValue(myValue);
        myField.xtype.inputEl.set({'placeholder':myValue});
    }
Run Code Online (Sandbox Code Playgroud)

我想要的是

if(myField.xtype == "tagfield"){
        // Automatic Focus  OR
        // Someway by which I can set the value
    }
Run Code Online (Sandbox Code Playgroud)

Ron*_*tel 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',
}
Run Code Online (Sandbox Code Playgroud)

通过此配置,如果您选择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);
}
Run Code Online (Sandbox Code Playgroud)

如果您仍然想聚焦同一字段并且正在加载标记字段的存储焦点,那么您可以使用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);                   
          }
       });
    }); 
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助。

如果您使用标记字段作为小部件,那么您可以使用onWidgetAttach配置widgetcolumn并在其上指定功能。

请参考链接