Skip to Content
Menu
This question has been flagged
1 Reply
7684 Views

i have function in JS like this handler when click will call a method custom_search in py file

_onclick_searchicon: function () {
            var self = this;
            var search = {};
            search.Input = self.$('.text_input').val().trim();
            console.log(typeof (search.Input));
            rpc.query({
                model: 'custom.search',
                method: 'custom_search',
                args: [search],
            }).then(function (data) {
                if (data.success === true) {
                    console.log(data);
                    self._result = data;
                }
            });
QWeb.render('systray_odoo_search.search_result', {
                widget: self
            });
}

now i want to get that data and render in xml file. I try to this but it not work 

<t t-name="systray_odoo_search.search_result">
    <t t-set="result" t-value="widget._result"/>
    <t t-if="_.isEmpty(result)">
      <div class="dropdown-item-text text-center o_no_activity">
        <span>No activities planned.</span>
      </div>
    </t>
    <t t-foreach="result" t-as="record">
      <div>Hello <t t-esc="record" />
      </div>
    </t>
  </t>
Avatar
Discard
Best Answer

Hello

there are many ways you can do it. I'll show you one method to write value of a variable in js to xml template

you can define global variables in your init function.

init: function(parent,options){
this._super(parent,options);
this.var_name = 0

create a div in xml template

<div class="some_class"/>

Edit it on button click, and write your value to div from js

$(".some_class").text(this.var_name);

Regards

MUHAMMAD IMRAN
Technical and Functional Consultant  (ODOO)


Softtar Technologies Pvt. Ltd. Contact : Pakistan (+92)-3037701373
 
Address:
  
Allhafeez Shopping Mall
Lahore
Pakistan  (Branch Office)
http://sofftar.com
Avatar
Discard
Related Posts Replies Views Activity
2
Jun 20
2894
2
Jul 24
287
2
Jun 23
40696
1
Dec 22
2319
2
Dec 22
3156