问题描述
我正在尝试在res.partner上自定义看板视图
我想使用
列出与该联系人关联的所有category_id,不<field name="category_id" widget="many2many_tags" options="{'color_field': 'color','no_create_edit': True}" />
我尝试使用Qwep t-foreach循环,但是不起作用,为什么?
<li t-foreach="record.category_id" t-as="item">
<t t-esc="item_value"/>
</li>
此打印
many2many
false
false
[object Object]
false
false
res.users
false
true
false
true
venditore
[object Object]
7,6
2record
我需要打印res.partner.category的名称
<div class="oe_kanban_details category_1 category_2">
...
谢谢
解决方法
您正在遍历记录# keep
c(0,1,1)
# 0 0 1 1 1
的属性。之所以得到该结果,是因为您使用了特殊变量$as_value,这些变量是以下属性的实际值。
category_id
raw_value包含记录集type
change_default
company_dependent
context
depends
domain
manual
readonly
relation
required
searchable
sortable
store
string
views
raw_value
value
,而value是显示记录数的字符串。
您可以尝试覆盖看板记录qweb上下文,以从ids
对象获取category_id
数据[{'color':,'display_name':,'id': },...]
。
示例
recordData
然后在看板视图中使用它,如下所示:
var KanbanRecord = require('web.KanbanRecord');
KanbanRecord.include({
_get_M2M_data: function (field) {
var categories = [];
if (field in this.recordData && this.recordData[field].data) {
categories = this.recordData.category_id.data;
}
return categories;
},_setState: function (recordState) {
var self = this;
this._super(recordState);
self.qweb_context['get_m2m_data'] = self._get_M2M_data.bind(self);
},});
在使用字段标记时,使用以下代码可获得相似的结果:
<t t-foreach="get_m2m_data('category_id')" t-as="category_data">
<t t-esc="category_data.data['display_name']"/>
</t>