其他分享
首页 > 其他分享> > 如何定义正确的XPath位置?

如何定义正确的XPath位置?

作者:互联网

我被设置为ssnid&作为看不见的字段,我们两个都是看不见的字段.但在我看来,两者都是显示的.看看XPath位置的问题.

任何人都可以帮我解决?

<?xml version="1.0"?>
<openerp>
    <data>
        <!-- 1st part of the sim_view start -->
        <record model="ir.ui.view" id="madulsima_plucker_form">
            <field name="name">madulsima.plucker.form</field>
            <field name="model">madulsima.plucker</field>
            <field name="inherit_id" ref="hr.view_employee_form" />
            <field name="type">form</field>
            <field name="arch" type="xml">
                <notebook position="inside">
                    <page string="Madulsima Plucker Fields">
                        <field name="reg_no" />
                        <field name="worker_name" />

                        <xpath expr="/form/notebook/page/group/field[@name='ssnid']"
                            position="attributes">
                            <attribute name="invisible">True</attribute>
                        </xpath>
                        <xpath expr="/form/notebook/page/group/field[@name='sinid']"
                            position="attributes">
                            <attribute name="invisible">True</attribute>
                        </xpath>

                    </page>
                </notebook>
            </field>
        </record>

        <record model="ir.actions.act_window" id="action_plucker_registration">
            <field name="name">Plucker Registration</field>
            <field name="res_model">madulsima.plucker</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
        </record>


        <menuitem id="menu_madulsima_plucker" name="Madulsima/Checkroll" />

        <menuitem id="menu_madulsima_plucker_registration" name="Plucker Registration"
            parent="menu_madulsima_plucker" action="action_plucker_registration" />
    </data>
</openerp>

我在view.xml中发布了我的整个代码

解决方法:

inherited view的arch字段中的根元素是定位符,它们应该识别父视图中的元素,然后可以根据特殊位置属性执行操作.

定位器必须具有position属性,可以是:

>< xpath>包含有效的expr属性的元素
XPath用于在父视图中定位单个元素的表达式;
>父视图中的任何有效视图元素;

继承的视图可以有多个根元素,以便对父视图执行多次更改.

您的示例不正确,因为您已嵌套了多个定位器:您的xpath元素位于页面元素内.请注意,3个元素在继承的视图中具有position属性:notebook元素和2个xpath元素.它们都需要位于视图架构的顶部,例如:

       <field name="arch" type="xml">
            <notebook position="inside">
               <!-- ... elements you want to add inside the parent notebook -->
            </notebook>
            <xpath expr="/form/notebook/page/group/field[@name='ssnid']"
                   position="attributes">
                <attribute name="invisible">True</attribute>
            </xpath>
            <xpath expr="/form/notebook/page/group/field[@name='sinid']"
                   position="attributes">
                <attribute name="invisible">True</attribute>
            </xpath>
        </field>

PS:如果您不熟悉XPath,您应该在线查看快速参考或备忘单,例如this one.

标签:python,openerp,xml
来源: https://codeday.me/bug/20190901/1780862.html