Javascript 尝试在odoo表单小部件中显示棋盘js,没有错误,没有碎片
嗨,我正试图在odoo后端的表单视图上显示,我终于制作了小部件来显示电路板,但是这些块被隐藏了,我不知道为什么,因为除了这些块之外,似乎工作得很好。如果我在选项中使用Javascript 尝试在odoo表单小部件中显示棋盘js,没有错误,没有碎片,javascript,openerp,odoo-8,odoo-9,odoo-view,Javascript,Openerp,Odoo 8,Odoo 9,Odoo View,嗨,我正试图在odoo后端的表单视图上显示,我终于制作了小部件来显示电路板,但是这些块被隐藏了,我不知道为什么,因为除了这些块之外,似乎工作得很好。如果我在选项中使用dragable:true,并移动一个隐藏的块,那么电路板将与所有块一起渲染。我是否在我的代码中遗漏了一些东西,棋盘没有很好地呈现?? 以下是mi小部件代码: (function (instance) { var _t = instance.web._t, _lt = instance.web._lt;
dragable:true
,并移动一个隐藏的块,那么电路板将与所有块一起渲染。我是否在我的代码中遗漏了一些东西,棋盘没有很好地呈现??
以下是mi小部件代码:
(function (instance) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
openerp.chess_base = function (instance, local) {
local.YourWidgetClassName = instance.web.form.FormWidget.extend({
start: function () {
this.$el.append('<div id="board" style="width: 300px">BOARD GOES HERE</div>'); // creating the board in the DOM
this.onBoard();
},
onBoard: function (position, orientation) {
if (!position) {
this.position = 'start'
} else {
this.position = position
}
if (!orientation) {
this.orientation = 'white'
} else {
this.orientation = orientation
}
this.el_board = this.$('#board');
this.cfg = {
position: this.position,
orientation: this.orientation,
draggable: false,
pieceTheme: '/chess_base/static/img/chesspieces/wikipedia/{piece}.png'
};
this.board = ChessBoard(this.el_board, this.cfg);
}
});
instance.web.form.custom_widgets.add('widget_tag_name', 'instance.chess_base.YourWidgetClassName');
}
})(openerp);
(函数(实例){
var\u t=instance.web.\u t,
_lt=instance.web.\u lt;
var QWeb=instance.web.QWeb;
openerp.chess_base=函数(实例,本地){
local.YourWidgetClassName=instance.web.form.FormWidget.extend({
开始:函数(){
this.$el.append('BOARD GOES HERE');//在DOM中创建板
这个.board();
},
车载:功能(位置、方向){
如果(!位置){
this.position='start'
}否则{
这个位置
}
如果(!方向){
this.orientation='white'
}否则{
这个方向=方向
}
this.el_board=this.$(“#board”);
this.cfg={
职位:这个职位,
方向:这个方向,
可拖动:错误,
pieceTheme:“/chess_base/static/img/chesspieces/wikipedia/{piece}.png”
};
this.board=棋盘(this.el_board,this.cfg);
}
});
add('widget_tag_name','instance.chess_base.YourWidgetClassName');
}
})(openerp);
我不知道为什么,但这解决了问题,如果有人向我解释,请
(function (instance) {
var _t = instance.web._t,
_lt = instance.web._lt;
var QWeb = instance.web.qweb;
openerp.chess_base = function (instance, local) {
local.ShowBoard = instance.web.form.FormWidget.extend({
start: function () {
this.$el.append('<div id="board" style="width: 300px">BOARD GOES HERE</div>');
this.show_board();
},
show_board: function () {
var Game = new instance.web.Model("chess.game"),
record_id = this.field_manager.datarecord.id,
record_name = this.field_manager.datarecord.name,
self = this;
self.el_board = self.$('#board');
Game.query(['pgn']).filter([['id', '=', record_id], ['name', '=', record_name]]).all().then(function (data) {
console.log(data);
self.cfg = {
position: data[0].pgn,
orientation: 'white',
pieceTheme: '/chess_base/static/img/chesspieces/wikipedia/{piece}.png'
};
ChessBoard(self.el_board, self.cfg);
});
}
});
instance.web.form.custom_widgets.add('board', 'instance.chess_base.ShowBoard');
}
})(openerp);
(函数(实例){
var\u t=instance.web.\u t,
_lt=instance.web.\u lt;
var QWeb=instance.web.QWeb;
openerp.chess_base=函数(实例,本地){
local.ShowBoard=instance.web.form.FormWidget.extend({
开始:函数(){
这个.$el.append('BOARD GOES HERE');
这个.show_board();
},
显示板:功能(){
var Game=new instance.web.Model(“chess.Game”),
record\u id=this.field\u manager.datarecord.id,
record\u name=this.field\u manager.datarecord.name,
self=这个;
self.el_board=self.$(“#board”);
Game.query(['pgn'])。filter([['id','=',record_id],'name','=',record_name]])。all()。然后(函数(数据){
控制台日志(数据);
self.cfg={
位置:数据[0]。pgn,
方向:'白色',
pieceTheme:“/chess_base/static/img/chesspieces/wikipedia/{piece}.png”
};
棋盘(self.el_board,self.cfg);
});
}
});
添加('board'、'instance.chess_base.ShowBoard');
}
})(openerp);