我试图在Odoo系统中添加一个第三方库,我使用的是Odoo 10。
我想集成的库是:https://github.com/ipluser/jquery-shifter,但是,我无法做到这一点。
我只是对视图上的列表进行了编码,并将库函数称为“shifter”。但不起作用。
这是我的密码。
odoo.define('crm_broadband.shifter', function(require){
'use strict'
$(function() {
$('.shifter').shifter({
maxShift: 1,
switcher: true,
responsive: true,
speed: 1000,
});
})})
<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>
<a class="shifter-forward" href="javascript:void(0)">forward</a>
<a class="shifter-backward" href="javascript:void(0)">backward</a>
</div>发布于 2017-01-17 09:33:33
编辑
实际上,问题是$('.shifter')找不到元素。在'web.FormView‘的'start’函数中使用‘this.$el.find(’.shifter‘)解决。
现在出现了另一个问题..。
一旦'ul.shifter‘结束包装空间,它就让它的元素转到一个新的行,取消脚本的功能。另外,如果我不设置'ul‘元素的宽度,脚本就不能单独设置它,使其为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;
}编辑端
好了解决了。我在我正在扩展的视图中声明的中调用了脚本,而不是文件开始时的“资产”模板。
<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>https://stackoverflow.com/questions/41682949
复制相似问题