阅读 102

Odoo14 js 怎么获取图片url链接

上内部代码:

 1 _getImageURL: function (model, field, id, placeholder) {
 2             id = (_.isArray(id) ? id[0] : id) || null;
 3             var isCurrentRecord = this.modelName === model && this.recordData.id === id;
 4             var url;
 5             if (isCurrentRecord && this.record[field] && this.record[field].raw_value && !utils.is_bin_size(this.record[field].raw_value)) {
 6                 // Use magic-word technique for detecting image type
 7                 url = ‘data:image/‘ + this.file_type_magic_word[this.record[field].raw_value[0]] + ‘;base64,‘ + this.record[field].raw_value;
 8             } else if (placeholder && (!model || !field || !id || (isCurrentRecord && this.record[field] && !this.record[field].raw_value))) {
 9                 url = placeholder;
10             } else {
11                 var session = this.getSession();
12                 var params = {
13                     model: model,
14                     field: field,
15                     id: id
16                 };
17                 if (isCurrentRecord) {
18                     params.unique = this.record.__last_update && this.record.__last_update.value.replace(/[^0-9]/g, ‘‘);
19                 }
20                 url = session.url(‘/web/image‘, params);
21             }
22             return url;
23         }

如何调用

1 image_url = self._getImageURL(‘res.users‘, ‘image_128‘, result[i].id, ‘‘);

第一个参数是模块名称,第二个是图像字段名称,第三个参数是记录id,第四个是占位符,也就是当生成url报错的时候默认url。

原文:https://www.cnblogs.com/watermeloncode/p/15222759.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐