美文网首页
odoo widget 渲染

odoo widget 渲染

作者: shallows2013 | 来源:发表于2019-01-30 11:42 被阅读0次

odoo 的 widget 渲染时,template 应该是必须的。

odoo.define('mycounter.js', function (require) {

    "use strict";

var Widget = require('web.Widget');

var Counter = Widget.extend({

    template: 'mycounter',

    events: {

        'click button': '_onClick',

    },

    init: function (parent, value) {

        this._super.apply(this, arguments);

        this.count = value;

    },

    _onClick: function () {

        this.count++;

        console.log(this.count)

        this.$('.val').text(this.count);

    },

});

return Counter;

qweb:

<?xml version="1.0" encoding="UTF-8"?>

<templates id="template" xml:space="preserve">

    <t t-name="mycounter">

        <span class="val"><t t-esc="widget.count"/></span>

        <button>Increment</button>

    </t>

</templates>

widget 写好后需要地方调用,fieldwidget  必须向 fieldRegistry 里  add,一般的 widget 需要被 new 和 添加到 dom,有 appendTo prependTo 等方法:

this.counter = new mycounter(self, 4);

this.counter.appendTo(self.$el);

问题:1,怎么通过 $ 定位元素;2,页面有生成,但是事件没触发。

问题2: 

<div>

        <span class="o_app"><t t-esc="widget.count"/></span>

        <button>Increment</button>

    </div>

必须被容器包着,作用范围在容器内

相关文章

网友评论

      本文标题:odoo widget 渲染

      本文链接:https://www.haomeiwen.com/subject/dswqsqtx.html