Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 开发与实施交流
  4. odoo10通过js获取到模型的json数据后,如果让数据在页面加载出来后以tree形式展示出来?

odoo10通过js获取到模型的json数据后,如果让数据在页面加载出来后以tree形式展示出来?

Scheduled Pinned Locked Moved Odoo 开发与实施交流
7 Posts 6 Posters 3.5k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    franciewang
    wrote on last edited by
    #1

    odoo10通过js获取到模型的json数据后,如果让数据在页面加载出来后以tree形式展示出来?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      digitalsatori
      管理员
      wrote on last edited by
      #2

      是要定义一个层级树吗?Odoo 10.0对有层级关系的数据结构是直接支持层级树的展示的。比如下面的HR的雇员层级列表视图:

              <record id="view_partner_tree2" model="ir.ui.view">
                  <field name="name">hr.employee.tree</field>
                  <field name="model">hr.employee</field>
                  <field name="field_parent">child_ids</field>
                  <field name="priority" eval="20"/>
                  <field name="arch" type="xml">
                      <tree string="Employees">
                          <field name="name"/>
                          <field name="work_phone"/>
                          <field name="work_email"/>
                          <field name="company_id" groups="base.group_multi_company"/>
                          <field name="department_id"/>
                          <field name="job_id"/>
                          <field name="coach_id" invisible="1"/>
                          <field name="parent_id" invisible="1"/>
                      </tree>
                  </field>
              </record>
      

      注意field_parent的定义。

      V11.0以后,Odoo去除了对field_parent的支持,不过社区中有位弟兄贡献了一个对tree view的扩展:https://github.com/openliu/odtree

      【上海先安科技】(tony AT openerp.cn)

      F 1 Reply Last reply
      0
      • JoshuaJ Offline
        JoshuaJ Offline
        Joshua
        管理员
        wrote on last edited by
        #3

        这个odtree看起来不错啊 👍

        【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

        1 Reply Last reply
        0
        • D digitalsatori

          是要定义一个层级树吗?Odoo 10.0对有层级关系的数据结构是直接支持层级树的展示的。比如下面的HR的雇员层级列表视图:

                  <record id="view_partner_tree2" model="ir.ui.view">
                      <field name="name">hr.employee.tree</field>
                      <field name="model">hr.employee</field>
                      <field name="field_parent">child_ids</field>
                      <field name="priority" eval="20"/>
                      <field name="arch" type="xml">
                          <tree string="Employees">
                              <field name="name"/>
                              <field name="work_phone"/>
                              <field name="work_email"/>
                              <field name="company_id" groups="base.group_multi_company"/>
                              <field name="department_id"/>
                              <field name="job_id"/>
                              <field name="coach_id" invisible="1"/>
                              <field name="parent_id" invisible="1"/>
                          </tree>
                      </field>
                  </record>
          

          注意field_parent的定义。

          V11.0以后,Odoo去除了对field_parent的支持,不过社区中有位弟兄贡献了一个对tree view的扩展:https://github.com/openliu/odtree

          F Offline
          F Offline
          franciewang
          wrote on last edited by
          #4

          @digitalsatori 在 odoo10通过js获取到模型的json数据后,如果让数据在页面加载出来后以tree形式展示出来? 中说:

          是要定义一个层级树吗?Odoo 10.0对有层级关系的数据结构是直接支持层级树的展示的。比如下面的HR的雇员层级列表视图:

          不是层级树,我是 想用ajax请求,拿到 json数据(后台是 dict的 list,用sql 查询出来的,但是没有保存到数据库),然后怎么把这些数据渲染,展示成odoo的tree 形式 (类比easyui,bootstrap-table 的展示方式)。
          另外,数据库的内容 ,odoo是通过什么方式,最终展示到前端的,中间的过程是什么?

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • H Offline
              H Offline
              HelloWorld
              wrote on last edited by
              #6

              10没用过,12重写search_view

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wft999
                wrote on last edited by
                #7

                参考方案:
                1)在views中定义一个client action:

                Test
                myproject.test
                current

                2)使用一个html a元素来触发这个action:


                Test

                3)编写一个js widget,具体写法参考文档:https://www.odoo.com/documentation/12.0/reference/javascript_reference.html#widgets;
                主要做三件事:
                a)设定模板template,根据要显示tree的需求去定制;
                b)定义willStart函数,使用._rpc()函数与后端通讯获得模型数据;
                c)定义start()函数,使用上一步获取的数据来render画面;
                完成widget之后,调用core.action_registry.add()来注册这个widget,使得点击上文的html a元素,就会显示这个widget

                4)最后一步,在后端模型类添加方法,用于被js _rpc()函数调用来获取数据;

                1 Reply Last reply
                0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Tags
                • Popular
                • Users
                • Groups