2011-07-05 73 views
3

我有从商店加载的组合框的项目,但是当组合框项目列表因为用户单击以“展开”而显示时会发生什么情况, ,它必须从商店代理'重新加载'数据。这会导致列表闪烁并变为未选中状态,迫使用户再次点击下拉列表。使用EXTjs预先加载组合框的项目

步骤1(在页面加载):

Page is loaded, combo not visible, but firebug shows priorities is already loaded

点击细胞进行编辑:

cell is clicked to edit, combo box now visible, firebug shows no changes

点击在组合框中的向下箭头。同样,这个ajax调用强制组合框自动关闭,迫使用户重新点击向下的箭头。

down arrow on dropdown clicked, firebug shows another ajax call was made.

查看

Ext.define('AM.view.card.BacklogList', { 
    extend: 'Ext.grid.Panel', 
    alias: 'widget.backlogcardlist', 

    title: 'Backlog', 
    store: 'BacklogCards', 

    selType: 'cellmodel', 
    plugins: [ 
     Ext.create('Ext.grid.plugin.CellEditing', { 
      clicksToEdit: 1 
     }) 
    ], 

    columns: [ 
     { header: 'ID', dataIndex: 'id' }, 
     { header: 'Name', dataIndex: 'name', field: 'textfield' }, 
     { 
      header: 'Priority', 
      dataIndex: 'priority_id', 
      renderer: function(value){ 
       if (value==3) 
       { 
        return "L"; 
       } 
       else if (value==2) 
       { 
        return "M"; 
       } 
       else 
       { 
        return "H"; 
       } 
      }, 
      width: 130, 
      field: { 
       xtype: 'combobox', 
       typeAhead: true, 
       store: 'Priorities', 
       displayField: 'name', 
       valueField: 'id', 
       listClass: 'x-combo-list-small' 
      } 
     } 
    ] 

}); 

商店:

Ext.define('AM.store.Priorities', { 
    extend: 'Ext.data.Store', 
    model: 'AM.model.Priority', 
    autoLoad: true, 

    proxy: { 
     type: 'ajax', 
     api: { 
      read: 'app/data/priorities.json', 
      update: 'app/data/updateUsers.json' 
     }, 
     reader: { 
      type: 'json', 
      root: 'priorities', 
      successProperty: 'success' 
     } 
    } 
}); 

priorities.json

{ 
    success: true, 
    priorities: [ 
     { 
      id    : 1, 
      name   : "High", 
      short_name  : "H" 
     }, 
     { 
      id    : 2, 
      name   : "Medium", 
      short_name  : "M" 
     }, 
      { 
      id    : 3, 
      name   : "Low", 
      short_name  : "L" 
     } 
    ] 
} 
+0

确保您使用* queryMode *'local',* autoLoad * true,并且在将其附加到组合前将您的商店实例化。这应该强制它在将其展示给最终用户之前获取值。 –

+0

嘿扭扭的梨!谢谢(你的)信息!将querymode设置为本地伎俩!如果您提交它作为答案,我会尽快接受:) – Robodude

回答

8

我相信你需要做的是设置queryMode什么: “本地”在th e组合框字段配置。

field: { 
xtype: 'combobox', 
queryMode: 'local', 
typeAhead: true, 
store: 'Priorities', 
displayField: 'name', 
valueField: 'id', 
listClass: 'x-combo-list-small' 
} 

the Ext JS Combobox API documentation (emphasis added)

在queryMode: '远程',组合框加载其存储与用户交互动态为主。

这通常用于“自动完成”类型的输入,并且在用户完成打字后,商店被加载

您的商店的autoLoad设置为true,这意味着您不应该将queryModel设置为本地问题,因为您的数据在创建时应该已经存储在商店中。我会说我没有深入挖掘解释行为,也许有人可以详细阐述组合框的错综复杂。