【发布时间】:2016-03-24 23:55:26
【问题描述】:
我正在编写一个 Odoo v9 小部件,它根据数据库中的设置和实际表单字段的连接来呈现 URL。
我认为数据库中的设置应该存在于 ir_config_parameter 中。我正在用我的模块插入一个默认值。
在渲染小部件时获取此值的最佳方法是什么?使用
进行异步 ajax 调用新模型(“ir.config_parameter”)
似乎有点沉重。有没有更好的方法来做到这一点?
谢谢。
小部件代码:
var UrlWidget2 = form_common.FormWidget.extend({
start: function() {
this._super();
this.field_manager.on("field_changed:ref", this, this.display_result);
this.display_result();
},
display_result: function() {
var ref = this.field_manager.get_field_value("ref");
if (!ref) return;
var baseUrl = 'https://example.com'; //this is the value I want to get from the setting in the database.
var url = baseUrl + '/foo/' + ref;
this.$el.html('<a href="' + url + '" target="portal">View Externally</a><br /><br/>');
}
});
【问题讨论】:
-
你想在哪里显示设置值?我的意思是它将是表单域?
-
从小部件内部 - 我正在编写 javascript - 我需要获取并使用配置设置。
-
显示你的 js 小部件。我做了类似的事情。也许我可以帮忙。
-
添加了小部件代码。
-
表格用什么模型?为什么不能为此添加
compute字段?