在 ExtJs 6 与以前版本中创建记录

Create record in ExtJs 6 vs Previous Versions

我注意到在 ExtJs 6 中创建记录的结果与旧版本不同。

我在使用 chrome 的控制台中有 运行 以下内容。我定义了以下模型。

 Ext.define('mymodel',{
   extend :'Ext.data.Model',
   fields : [
     {name:'firstname'}
  ]
});

然后我用这个模型创建一条记录。

 var rec = Ext.create(mymodel,{
     firstname: 'Peter',   
     lastname: 'Venkman'
 });

当我从这条记录中获取数据时

rec.getData();

结果是

ExtJs 6

Object {firstname: "Peter", lastname: "Venkman", id: "mymodel-1"}

ExtJs 4

Object {firstname: "Peter", id: undefined}

在 ExtJs 6 中

lastname 

正在创建,但未在模型中定义。有谁知道这是为什么?我在文档中找不到的更改。

What’s New in Ext JS 5:

The Model constructor no longer extracts fields from the data object it is given but rather adopts it and upgrades it based on the converters and default values from your defined fields. This means that you no longer need to define every field you want to keep on your record. As long as the server sends the data in the desired format, those properties will remain on the record’s data object. These undeclared fields are assumed to be persistent, so changes will be tracked and included in saves back to the server.