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。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?