在网格中使用 EXTjs 模型的验证器属性
我有一个非常标准的网格 ->商店-> Extjs4 中的模型架构。要求是每条记录中的八个字段中有五个是强制性的,所以我想使用模型验证配置:
Ext.define('TransferRecord', { extend: 'Ext.data.Model',
fields: transferRecordFields,
idProperty: 'RID',
validations: [
{ type: 'presence', field: 'FNAME' },
{ type: 'presence', field: 'LNAME' },
{ type: 'presence', field: 'GENDER' },
{ type: 'presence', field: 'DOB' },
{ type: 'presence', field: 'TRANSFER_TYPE'}]
});
这种工作方式 - 当商店同步时,它不会将新记录同步到数据库,除非定义了所有这些字段。但是,除了同步未成功完成之外,没有向用户提供任何反馈。
理想情况下,我想突出显示有问题的字段,以便用户知道哪些字段仍然需要值(反之亦然 - 当它们正常时清除突出显示)。我知道如果我为每条记录调用 record.validate ,我可以获得错误对象列表,但我不确定如何将该信息转换为 X 行的单元格,字段“FNAME”需要更改颜色(或找到该单元格的最佳方法,以便我可以应用更改)。
我觉得我错过了一些简单的东西 - 可能有一个 API 已经可以帮助我了,但我找不到它。
I have a pretty standard Grid -> Store -> Model architecture in Extjs4. The requirement is that five of my eight fields in each record are mandatory, so I thought to use the Model valdiations config:
Ext.define('TransferRecord', { extend: 'Ext.data.Model',
fields: transferRecordFields,
idProperty: 'RID',
validations: [
{ type: 'presence', field: 'FNAME' },
{ type: 'presence', field: 'LNAME' },
{ type: 'presence', field: 'GENDER' },
{ type: 'presence', field: 'DOB' },
{ type: 'presence', field: 'TRANSFER_TYPE'}]
});
This sort of works - when the store syncs, it will not sync new records to the database unless all those fields are defined. However, there is no feedback to the user, other than the sync does not complete successfully.
Ideally, I would like to highlight the offending fields so the user knows which ones still need values (and conversely - clear the highlighting when they are ok). I know that if I call record.validate for each record, I can get an list of error objects, but I am not sure of how to translate that information to the cell at row X, Field 'FNAME' needs to change color (or the best way to find that cell so I can apply the change).
I feel like I'm missing something simple - that there is probably an API that already helps me here, but I can't find it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现 EXTjs 示例中的示例自定义渲染器并不完整 - 渲染器确实采用了示例中未显示的许多额外参数。
我可以通过定义以下渲染器函数并将其分配给每一列来使其工作:
I have discovered that the example custom renderer in the EXTjs examples is not complete - that the renderer does take a lot of extra parameters that the example did not show.
I was able to get it working by defining the following renderer function and assigning it to each column: