由于很多时候需要dom生成以后才能进行绑定操作,所以这里就需要将操作放到这个函数里面,如client_action, 主要作用是避免绑定的时候dom还不存在。
xxxxxxxxxx
1
odoo.define('funenc.view_plan_by_time_line', function (require) {
2
"use strict";
3
4
var core = require('web.core');
5
var ListController = require('web.ListController');
6
var AbstractAction = require('web.AbstractAction');
7
var ControlPanelMixin = require('web.ControlPanelMixin');
8
var sub_list_widget = require('funenc.sub_list_widget');
9
var qweb = core.qweb;
10
11
var view_plan_by_time_line = AbstractAction.extend(ControlPanelMixin, {
12
year: undefined,
13
items: [],
14
groups: [],
15
time_line: [],
16
template: 'funenc.view_plan_by_time_line',
17
18
jsLibs: ['/metro_park_maintenance/static/lib/vis/vis-timeline-graph2d.min.js'],
19
cssLibs: ['/metro_park_maintenance/static/lib/vis/vis-timeline-graph2d.min.css'],
20
21
init: function (parent, action) {
22
this._super.apply(this, arguments)
23
this.year = action.context.year || action.params.year
24
},
25
26
/**
27
*
28
*/
29
on_attach_callback: function () {
30
// Configuration for the Timeline
31
var options = {
32
start: this.start_date,
33
end: this.end_date,
34
height: "600px"
35
};
36
37
// Create a Timeline
38
this.time_line = new vis.Timeline(this.$(".time_line")[0]);
39
40
// 不加timeout会有问题
41
this.time_line.setOptions(options);
42
this.time_line.setGroups(self.groups);
43
this.time_line.setItems(self.items);
44
},
已复制
对于widget的话append的时候可以注册回调
xxxxxxxxxx
1
function _notify(content, callbacks) {
2
_.each(callbacks, function (c) {
3
if (c.widget && c.widget.on_attach_callback) {
4
c.widget.on_attach_callback(c.callback_args);
5
}
6
});
7
core.bus.trigger('DOM_updated', content);
8
}
9
10
var dom = {
11
DEBOUNCE: 400,
12
13
/**
14
* Appends content in a jQuery object and optionnally triggers an event
15
*
16
* @param {jQuery} [$target] the node where content will be appended
17
* @param {htmlString or Element or Array or jQuery} [content] DOM element,
18
* array of elements, HTML string or jQuery object to append to $target
19
* @param {Boolean} [options.in_DOM] true if $target is in the DOM
20
* @param {Array} [options.callbacks] array of objects describing the
21
* callbacks to perform (see _notify for a complete description)
22
*/
23
append: function ($target, content, options) {
24
$target.append(content);
25
if (options && options.in_DOM) {
26
_notify(content, options.callbacks);
27
}
28
},
已复制