2

What is the correct approach to be followed for setting value to a combobox in Extjs 4.2. Prior to Extjs 4.2, the combobox with remote store was set using the following piece of code.

var book= Ext.create('Test.model.Book', bookValues);
bookCombo.store.loadRawData([book]);
bookCombo.setValue(book.getId());
bookCombo.setRawValue(book.get('name'));
bookCombo.displayTplData = book.data;
bookCombo.fireEvent('change', bookCombo, book.getId());

But the above piece of code doesn't set the value of the remote combo correctly since 4.2.

4

2 回答 2

1

这让我发疯,但最终我有一个解决方案。

首先,您必须为商店定义一个模型,然后您可以使用新模型实例设置值。

// model
      Ext.define('UserSearchFieldModel', {
        extend: 'Ext.data.Model',
        fields: [
          {name: 'user_id',  type: 'string'},
          {name: 'displayname', type: 'string'}
        ]
      });

// store
      UserSearchField_Store = Ext.create('Ext.data.Store', {
        model: 'UserSearchFieldModel',
        remoteFilter: true,
        proxy: {
          type: 'ajax',
          url: '...',
          reader: {
            type: 'json',
            root: 'userList'
          }
        }
      });

// field
    {
      itemId: 'userField',
      xtype: 'combo',
      queryMode: 'remote',
      hideTrigger: true,
      store: UserSearchField_Store,
      displayField: 'displayname',
      valueField: 'user_id'
    }

// set a initial value on load
    this.down('#userField').setValue(Ext.create('UserSearchFieldModel', {
      id: initialUser.id,
      displayname: initialUser.name
    }));
于 2015-03-27T16:20:40.320 回答
0

我认为在加载数据bookCombo.setValue(book.getId());之后应该足以设置组合中的值。设置值后,更改事件应自动触发。调用后自动调用休息setValue

我认为你自己打电话给所有这些事情会搞砸。

于 2013-07-29T06:22:25.157 回答