添加新行或编辑现有行时,Rowediting插件的奇怪行为

时间:2019-07-01 08:44:13

标签: extjs plugins extjs6

在添加新行或第一次编辑现有行时(在渲染组件之后),Rowediting插件的奇怪行为:错误的编辑器大小和偏心按钮。 是虫子吗? 如果是错误,是否有解决此问题的方法?

Ext JS 6.7.0

提琴:https://fiddle.sencha.com/#view/editor&fiddle/2sqf

1 个答案:

答案 0 :(得分:1)

我曾经遇到过这个问题,虽然我没有详细的答案,但是我有一些解决方案。

当您使用带有inline data的商店(未定义正确的Ext.data.Model),并且要添加以Ext.data.Model实例化的新记录时,就会发生此问题。

这是两种解决方法:

第一个解决方案:添加内联数据

您没有添加Ext.data.Model的实例,而是添加了具有必填字段的简单json数据。

  // in your handler...

  // create the record as json
  jsonRecord =  {
     name: '',
     email: '',
     phone: ''
  }

  // Adding to the store converts the json data into records
  const addedRecords = store.add(jsonRecord);

  // Since we are only adding a single record, we edit the idx 0
  rowediting.startEdit(addedRecords[0]);

第二个解决方案:为您的数据定义一个模型

Ext.define('YourModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name',  type: 'string'},
        {name: 'email',   type: 'string'},
        {name: 'phone', type: 'string'}
    ]
});

并使用此模型创建您的商店...

Ext.create('Ext.data.Store', {
    storeId: 'simpsonsStore',
    model: 'YourModel',          // Set model here
    // fields:[ 'name', 'email', 'phone'],
    data: [
        { name: 'Lisa', email: 'lisa@simpsons.com', phone: '555-111-1224' },
        { name: 'Bart', email: 'bart@simpsons.com', phone: '555-222-1234' },
        { name: 'Homer', email: 'homer@simpsons.com', phone: '555-222-1244' },
        { name: 'Marge', email: 'marge@simpsons.com', phone: '555-222-1254' }
    ]
});

...并创建新记录。

   // In your handler

   // Create the record with your model
   record = Ext.create('YourModel');

   // Add to the store
   store.add(record);

   // Edit the record instance
   rowediting.startEdit(record);

在两种方法中,更新行也将更新新添加的记录。

希望这会有所帮助