小智 8
查看继承
Odoo不是修改现有视图(通过覆盖它们),而是提供视图继承,其中子视图"扩展"视图应用于根视图之上,并且可以添加或删除其父视图中的内容.
扩展视图使用inherit_id字段引用其父级,而不是单个视图,其arch字段由任意数量的xpath元素组成,用于选择和更改其父视图的内容:
<!-- improved idea categories list -->
<record id="idea_category_list2" model="ir.ui.view">
<field name="name">id.category.list2</field>
<field name="model">idea.category</field>
<field name="inherit_id" ref="id_category_list"/>
<field name="arch" type="xml">
<!-- find field description and add the field
idea_ids after it -->
<xpath expr="//field[@name='description']" position="after">
<field name="idea_ids" string="Number of ideas"/>
</xpath>
</field>
</record>
Run Code Online (Sandbox Code Playgroud)
expr在父视图中选择单个元素的XPath表达式.如果它不匹配任何元素或多个位置,则引发错误
Operation to apply to the matched element:
inside
appends xpath's body at the end of the matched element
replace
replaces the matched element by the xpath's body
before
inserts the xpath's body as a sibling before the matched element
after
inserts the xpaths's body as a sibling after the matched element
attributes
alters the attributes of the matched element using special attribute elements in the xpath's body
Run Code Online (Sandbox Code Playgroud)
小费
匹配单个元素时,可以直接在要查找的元素上设置position属性.下面的两个遗产都会给出相同的结果.
<xpath expr="//field[@name='description']" position="after">
<field name="idea_ids" />
</xpath>
<field name="description" position="after">
<field name="idea_ids" />
</field>
Run Code Online (Sandbox Code Playgroud)
希望这有帮助.
| 归档时间: |
|
| 查看次数: |
5860 次 |
| 最近记录: |