[英]How to use RPC query in JavaScript with search method in Odoo 11 / 12?
I have following code: 我有以下代码:
odoo.define('module_name.templates', function(require){
"use strict";
$(document).ready(function() {
var rpc = require('web.rpc');
$('#query').click(getProductBySKU);
function getProductBySKU(){
var domain = [];
var args = [domain];
var res = rpc.query({
model: 'product.template',
method: 'search',
args: args
}).then(function (products) {
console.log(product); });
};
});
});
With that code it gives me Array of numbers, ex [1,2]. 有了该代码,它就给了我数字数组,例如[1,2]。 Length of array is equal to number of entries I have, but no objects at all.
数组的长度等于我拥有的条目数,但根本没有对象。 If I replace the domain with something like [('id', '=', 2)] I get error "Int object is not subscriptable".
如果将域替换为[('id','=',2)]之类的错误,则会出现错误“ Int对象不可下标”。
So my question : is it possible to get list of objects from database with search method or at least get the fields from specified DB entries. 所以我的问题是 :是否可以通过搜索方法从数据库中获取对象列表,或者至少从指定的DB条目中获取字段。
I also tried with search_read method. 我也尝试了search_read方法。 Like this:
像这样:
odoo.define('shift_knob.templates', function(require){
"use strict";
$(document).ready(function() {
var rpc = require('web.rpc');
$('#query').click(getProductBySKU);
function getProductBySKU(){
console.log("Hello world!");
var domain = [('id', '=', 2)];
var args = [domain];
var res = rpc.query({
model: 'product.template',
method: 'search_read',
args: [[], ['name', 'default_code']]
/* args: args */
}).then(function (products) {
console.log(products); });
};
});
});
I get the list of objects with name, default code, but I can use only id as identificator and not the fields I want 我得到具有名称,默认代码的对象列表,但是我只能使用id作为标识符,而不能使用我想要的字段
Change 更改
[('id', '=', 2)];
To 至
[ ['id', '=', 2], [] ];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.