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

how to get database values into java script   which is placed in xml 


i am using postgre and odoo10

Avatar
Discard
Best Answer

Hi Basha,

Please elaborate your question.

Or you could call python method in java script to call a python function. for example in java script new instance.web.Model(<model.name.in.quotes>).function_name(<yourfunction_name>)(<arguments>)



Avatar
Discard
Author

thank you can you please share any sample code

Hi

Suppose, you want to call has_group from res.users

var Users = new instance.web.Model('res.users');

Users.call('has_group', [<group_name>]).done(function res){ });

Thanks !

Author

hi sushma

i didn't understood clearly

suppose i want phone_code from res.country

please specify the syntax for it

Hi,

Actually you can have country object in JS, directly you look for like country.phone_code.

Else

# JS

this.model_country = new Model("res.country");

self.model_country.call("get_phone_code", [obj,'IN']).then(function(result){

var phone_code = result['phone_code'] ; });

#python

@api.multi

def get_phone_code(self, Country_code):

res = {}

phone_code = # write code to find country from code

res['phone_code'] = phone_code

return res

Author

please still i havent got solution for this

as per your above js code

i unable to get data

i tried by putting the phone_code in alert

This an example I've shared you, just refer and try as per you needs. Even though you will get lot of example withing odoo addons

Author

Hi please any solution

<t t-foreach="values" t-as="value">

<input type="hidden" t-att-value="value.editor1" id="aaa"/>

<script type="text/javascript">

var a= document.getElementById("aaa").value;

alert(a);

document.getElementById("kkkr").innerHTML = a;

</script>

<span id="kkkr"> </span>

here iam getting only first record every time

How to get all records present in the table

Hi Basha,

You're fetching single values through document.getElement(), you need to call python method to JS, Please refer my above example for calling python into JS.

Thanks!

Related Posts Replies Views Activity
2
Jun 24
489
1
Dec 23
574
1
Apr 23
668
1
Mar 23
1250
0
Dec 22
1137