问题
Can anyone help me with creating a dropdown list in the POS partner screen. I added this in the pos.xml file, but the dropdown is empty. Thanks
<div class='client-detail'>
<span class='label'>CustomerGroup</span>
<select class='*what to place here?*' name='group_id'>
<option value=''>None</option>
<t t-foreach='*what to place here?*' t-as='group'>
<option t-att-value='group.id' t-att-selected="partner_group_id ? ((group.id === partner.group_id[0]) ? true : undefined) : undefined">
<t t-esc='group.name'/>
</option>
</t>
</select>
</div>
I've copied this from the country dropdown list.
回答1:
example.js
you can set values of self.groups and self.partners as per your requirement.
render_function : function(){
var self = this;
var template_window = $(QWeb.render("template_name", {
groups : self.groups,
partners : self.partners,
}));
template_window.appendTo(this.$el);
},
example.xml
<div class='client-detail'>
<span class='label'>CustomerGroup</span>
<select class='group_class' name='group_id'>
<option value=''></option>
<t t-foreach='groups' t-as='group'>
<option t-att-value='group.id' t-att-selected="partner_group_id ? ((group.id === partner.group_id[0]) ? true : undefined) : undefined">
<t t-esc='group.name'/>
</option>
</t>
</select>
</div>
you can set any class name at place of "group_class" and you can use this class name to get selected values from gui to your js code.
t-foreach='groups' here groups is name of dictionary key that you passed from js at time of rendering the template.
来源:https://stackoverflow.com/questions/35890929/odoo-pos-create-a-dropdown-list