Odoo 10 - 集成第三方JS库

时间:2017-01-16 18:36:09

标签: javascript openerp

我正在尝试将第三方库添加到Odoo系统中,我正在使用Odoo 10。

我想要整合的库是:https://github.com/ipluser/jquery-shifter但是,我无法实现这一目标。

我只是在视图上编码列表并调用库函数'shifter'。但它不起作用。

这是我的代码。

const ranks = Array('A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K');

})

odoo.define('crm_broadband.shifter', function(require){
'use strict'

$(function() {
    $('.shifter').shifter({
        maxShift: 1,
        switcher: true,
        responsive: true,
        speed: 1000,
    });
})

1 个答案:

答案 0 :(得分:0)

修改

实际上问题是$(' .shifter')无法找到该元素。 使用'这个。$ el.find(' .shifter')' 解决了' start' ' web.FormView' 的功能。

现在出现另一个问题..

只要' ul.shifter' 结束了包装器空间,它就会让其元素转到新行,取消脚本功能。 另外,如果我没有设置' 元素的宽度,则脚本无法自行设置,使其宽度为0px。

有人可以帮助我吗?

感谢。

instance.web.FormView.include({

    start: function() {
        this._super.apply(this, arguments)

        // WRAP CHILDREN IN 'li > ul > div'
        this.$el.find('.oe_button_box')
            .children()
            .wrapAll("<div class='shifter_wrap'></div>")
            .wrapAll("<ul class='shifter'></ul>")
            .wrap("<li class='shifter_element'></li>")

        this.$el.find('.shifter').shifter()
    },
})


.shifter-wrap {
  overflow: hidden !important;
  height: 40px !important;
}
.shifter {
  height: 40px;
  margin-left: 0 !important;
  max-width: @sheet-max-width !important;
  min-width: 132px !important;
  overflow: hidden !important;
}
.shifter_element {
  width: 132px !important;
  display: inline-block !important;
  float: left !important;
}

编辑结束

好的,解决了。 我在&lt; head &gt;内调用了我的脚本。在我正在扩展的视图中声明,而不是文件开头的&quot;资产&#39; 模板。

<record id="crm_case_form_view_oppor_inherit" model="ir.ui.view">
        <field name="name">crm.lead.form.opportunity.inherit</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
        <field name="arch" type="xml">

            <xpath expr="//div[@name='button_box']/button[1]" position="before">

                <head>
                    <meta charset="UTF-8"/>
                    <meta name="renderer" content="webkit"/>
                    <meta name="viewport" content="width=device-width, initial-scale=1"/>
                    <script type="text/javascript" src="/crm_broadband/static/src/js/shifter.js"/>
                </head>


                <div class="shifter-wrap">
                    <ul class="shifter">
                        <li>
                            <button class="oe_stat_button oe_broadband_btn" name="open_create_popup"
                                    icon="fa-plus" type="object"
                                    attrs="{'invisible': [('partner_id', '!=', False)]}"
                                    sequence="0">
                                <field string="Broadband" name="name" widget="statinfo"/>
                            </button>
                        </li>
                    </ul>
                </div>
            </xpath>
       </field>
</record>
相关问题