在 ExtJS 3.x 中,我能够使用 Store 的“fields”属性,但在 ExtJS 4 中我似乎必须绝对使用模型。这很好,但就我而言,它不是静态模型,我需要动态定义字段,有时还需要更改它们。
我可以重新创建一个模型,但我需要使用不同的名称,因为显然不可能修改现有模型,也无法删除它。如果我尝试使用同名的 Ext.regModel,ExtJS 就会崩溃。
感谢您的帮助!
4.1 更新:
作为更新...在 4.1 中现在有一个静态方法setFields
可用于定义模型原型字段。它在控制器的 init 方法中运行良好。
当我这样做时,我想在模型类中定义一些静态字段,然后更动态地设置一些字段。不幸的是新setFields
method replaces所有字段都有参数,但处理起来很容易。
此示例使用 MVC 模式,其中我的模型和商店包含在控制器的model
数组和store
数组(为我提供下面使用的方便的吸气剂):
Ext.define('ST.controller.Main', {
extend: 'Ext.app.Controller',
models: ['User', 'Reference'],
stores: ['CurrentUser', 'PermissionRef'],
views: ['MainPanel'],
init: function() {
var me = this;
me.getPermissionRefStore().on('load', function(store, records) {
var model = me.getUserModel();
// this returns the static fields already defined
// in my User model class
fields = model.prototype.fields.getRange();
// add the permission options (dynamic fields) to the static fields
Ext.each(records, function(permission) {
fields.push({name: permission.get('name'), type: 'bool'});
});
// 4.1 method to update the User model fields
model.setFields(fields);
// now load the current user (it will use the updated model)
me.getCurrentUserStore().load();
});
}
});
The User
模型和CurrentUser
存储的创建与常规的非动态模型完全相同,并且存储将包含在各自的控制器数组中,“用户”模型只是缺少如上所示添加的动态字段。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)