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。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM