javascript - 如何在 POS models.js 中扩展初始化函数
问题描述
我想在初始化函数中添加变量,但我不知道如何正确执行
这是我现在尝试过的
odoo.define('tw_pos_inherit_model.attemptInherit', function (require) {
"use strict";
var POSInheritmodel = require('point_of_sale.models');
var _super_order = POSInheritmodel.Order.prototype;
POSInheritmodel.Order = POSInheritmodel.Order.extend({
initialize: function(session,attributes){
var self = this;
this.additional_discount = 0;
_super_order.initialize.apply(this,arguments);
},
我试过做这里所说的,但这个例子是针对 PosModel 而不是 Order
这是错误
point_of_sale.assets.js:79 Cannot read property 'name' of undefined TypeError: Cannot read property 'name' of undefined
at Engine.eval (eval at _render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3416:73), <anonymous>:50:34)
at Engine._render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3415:296)
at Engine.render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3415:151)
at Engine._render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3419:57)
at Engine.render (http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3415:151)
at Class.render_orderline (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:306:5014)
at Class.renderElement (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:308:354)
at Class.replace (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:307:423)
at Class.start (http://localhost:8071/web/content/723-a89f195/point_of_sale.assets.js:325:810)
at http://localhost:8071/web/content/319-5a1ade2/web.assets_common.js:3684:52
解决方案
您不需要var self = this;
,因为以后不使用它。
此外,您很可能需要从初始化函数返回一些内容。
_super_order.initialize.apply(this,arguments);
应该:
return _super_order.initialize.apply(this,arguments);
推荐阅读
- javascript - 无法在 Nest.js 框架中将 TypeORM 连接到 Heroku Postgres 数据库
- typescript - Vue inline CKEDITOR 4 内容未更新
- django - 使用 Wagtail 进行 Factory Boy 测试失败:TypeError: Field 'id' expected a number but got {}
- ios - Mapbox iOS 在顶部获得注释?
- lisp - Common lisp 中的插入排序
- c++ - boost::asio::async_read_until 不要截断输入消息
- regex - 正则表达式:如果接下来的 5 个字符包含 3 次出现而不是字符 k,则匹配一个字符串
- python - 使用 pandas(Python)打开 .dat 文件后不需要的合并列
- hexo - Hexo g -d 不起作用,无法检测到版本
- postgresql - 指向 Postgres 的 LAMBDA current_timestamp