简体   繁体   中英

How to read QWeb variable in javascript in Odoo 10?

i want to use qweb variables in script.

    <t t-set="test_var" t-value="TEST_VAR_VALUE"/>              

    <script type="text/javascript">

    var result = <t t-esc="test_var"/>;
document.getElementById("div_id").innerHTML = result;
</script>

i tried above code but it doesn't work.

You don't have to give a t-set option for this.You can simply use a span for this.

 <span class="test_class" t-att-data-test_var="TEST_VAR_VALUE"/>
    <script>
        $( function() {
            var result = $( ".test_class" ).data().test_var;
            });
    </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM