When i do Ctrl+U, there is below json in my page DOM
<script type="text/x-magento-init">
{
"#country": {
"regionUpdater": {
"optionalRegionAllowed": true,
"regionListId": "#region_id",
"regionInputId": "#region",
"postcodeId": "#zip",
"form": "#form-validate",
"regionJson": {
"config": {
"show_all_regions": true,
"regions_required": [
"AU",
"BR",
"CA",
"CN",
"CO",
"HR",
"EE",
"IN",
"LV",
"LT",
"MX",
"PL",
"RO",
"ES",
"CH",
"US"
]
}
}
}
}
}
</script>
I want to get regionJson value in my custom js file, Can someone please give me any solution or any idea to achieve this.
3
Answers
You can get regionJson like this,
Try something like this, ideally # is not valid in json key name.
So i used replace method to remove it, then parse it
Working Demo
Batter Solution would be to find the
phtml
file which call might be calling block or function which are providing theregionJson
data and you can get the same data in your js file by invoking it usingtext/x-magento-init
and pass config same as passed in your question you can also store that in the javascript globalwindow
object and get this value later in the js file.