如何从extjs中的定制模型扩展.
有没有什么方法可以直接参与用户和企业用户字段的领域,当我将在下面的例子中引用BusinessUser类的字段.
Ext.define('User',{ extend: 'Ext.data.Model',fields: [ {name: 'name',type: 'string'},{name: 'age',type: 'int'},{name: 'phone',{name: 'alive',type: 'boolean',defaultValue: true} ],}); Ext.define('BusinessUser',{ extend: 'User',fields: [ {name: 'businessType',{name: 'company',type: 'string'} ],});
解决方法
您不需要手动加入这些字段,因为它自动完成.根据您的问题检查代码中的输出:
Ext.define('User',}); // instantiating a User object var u = Ext.create('BusinessUser',{ name: 'John Doe',age: 30,phone: '555-5555' }); // instantiating a BusinessUser object var bu = Ext.create('BusinessUser',{ name: 'Jane Doe',age: 40,phone: '555-5556',businessType: 'analyst',company: 'ACME' }); console.log(Ext.getClassName(bu)); // "BusinessUser" console.log(Ext.getClassName(u)); // "User" console.log(u instanceof User); // true console.log(bu instanceof User); // true console.log(u instanceof BusinessUser); // false console.log(bu instanceof BusinessUser); // true console.log(u instanceof Ext.data.Model); // true console.log(bu instanceof Ext.data.Model); // true console.log(u instanceof Ext.data.Store); // false,just to check if it's not returning true for anything console.log(bu instanceof Ext.data.Store); // false console.log("name" in u.data); // true console.log("name" in bu.data); // true console.log("company" in u.data); // false console.log("company" in bu.data); // true