如何在Odoo 17中通过父组件使用JS更新字段值
Odoo 17 中更新Many2one字段值的替代方法
Odoo 17 前端架构做了调整,原有的component.props.update()方法已被移除,取而代之的是通过record对象来更新字段值。
针对你的Many2one字段清空场景,直接调用component.props.record.update()方法即可,示例代码如下:
if (component.props.type === "many2one") { // 将 component.props.name 替换为你的实际字段名(如 'partner_id') component.props.record.update({ [component.props.name]: [] }); }
关键说明:
component.props.record是当前字段所属的记录对象,所有字段的更新操作都通过它的update方法完成- 传入
update的参数是一个键值对对象,键为字段名称,值为要设置的新值(Many2one清空传[]即可) - 如果需要同时更新多个字段,可在对象中添加多个键值对,比如:
record.update({ field1: value1, field2: value2 })
内容的提问来源于stack exchange,提问作者Yassir Irfan
相关产品推荐
相关产品推荐

