【问题标题】:How to use RPC query in JavaScript with read method, for get all rows from table. In Odoo 13?如何在 JavaScript 中通过 read 方法使用 RPC 查询,从表中获取所有行。在 Odoo 13 中?
【发布时间】:2020-11-07 16:06:16
【问题描述】:

我使用 odoo 13。我尝试从我的表中获取所有行。我应该在我的 arg 中传递什么,以便一次获取所有字符串?

我的代码:

 var res = rpc.query({
            model: 'my model',
            method: 'read',
            args: [????]
        }).then(function (data) {
            console.log(data); });
        };

【问题讨论】:

  • 您是否已经尝试过使用空括号?
  • @Alonso 是的,我特雷德。
  • 我会尝试提供一些虚拟条件作为参数,例如“args: [[['id', '>', 0]]]”。

标签: javascript sql database rpc odoo-13


【解决方案1】:

Павел Храпун

在 (python) model 上调用 method 并通过 RPC 访问记录数据。

var id = this.id; // (pass the record of ID which you want to read the data)
var res = rpc.query({
        model: 'Your Model',
        method: 'read', // method which you wanna call
        args: [[id], ['name']], // First argument to pass the ID along with second args pass fields
    }).then(function (data) {
        console.log(data); });
    };

【讨论】:

    【解决方案2】:

    args 可以获取上下文、域和字段作为参数。要获取所有记录,您应该使用空域和字段,例如:

    var res = rpc.query({
                model: 'my model',
                method: 'read',
                args: [[], []] // empty parameters
            }).then(function (data) {
                console.log(data); });
            };

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-06
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多