我有一个Wix网站,我在页面上使用Google Maps自动填充表格来获取地址并将其传递给“ wix存储”,该存储允许变量在用户“会话”中浮动,然后我将其提取并将其推送到HTML框,其中有一个小部件,该小部件使用src为我提供该小部件的值,该小部件将被我称为avm小部件。我的问题是avm小部件尝试过快地计算房屋的价值,因此页面代码没有时间将地址发送给HTML,而HTML没有时间将其传递给小部件。我了解到wix并不是一个很多人都将代码弄乱的平台。我已经尝试了几乎所有我能想到的东西,但一切都不起作用。
这是我编写的代码。
<script>
var q;
function get_adress() {
//gets the adress from the page code
window.onmessage = (event) => {
q = event.data;
}
return window.q;
}
var adress = get_adress();
var rprAvmWidgetOptions = {
//this is the var that the rpr widget needs
Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
Query: adress,
CoBrandCode: "btso48",
ShowRprLinks: false
}
</script>
<script language="JavaScript">
//This was my best shot at a script that could hold the loading of the src so that I could by time for my code to get the var.
function helper() {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//www.narrpr.com/widgets/avm-widget/widget.ashx/script';
head.appendChild(script);
}
</script>
这是小部件的常规代码。查询是我需要替换的。
<script>
var rprAvmWidgetOptions = {
Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
Query: "3911 E Douglas Loop, Gilbert, AZ 85234",
CoBrandCode: "btso48",
ShowRprLinks: false
}
</script>
<script src="//www.narrpr.com/widgets/avm-widget/widget.ashx/script">
</script>
这是我的jquery wix称其为“页面代码”
// For full API documentation, including code examples, visit
http://wix.to/94BuAAs
import wixData from "wix-data"; // activates wix-data
import {session} from 'wix-storage'; // activates wix-storage
$w.onReady(function () {
let start = session.getItem('1',start);// gets the adress from storage
setTimeout(
function()
{
messageSendButton_onClick(start); // waits for html box to load then sneds the adress
}, 1000);
});
export function messageSendButton_onClick(start) {
// send message to the HTML Component
$w('#html1').postMessage(start);
}
答案 0 :(得分:0)
我不能很好地解释事情,但我会建议一种方法。
PageCode
import wixData from "wix-data"; // activates wix-data
import {session} from 'wix-storage'; // activates wix-storage
$w.onReady(function () {
let start = session.getItem('1',start);// gets the adress from storage
$w("#htmlbox").postMessage({address : start}); }); // send address to wix html box container
});
页面脚本
<script>
window.onmessage = (event) => {
if (event.data) {
let _data = event.data;
let address = _data.address; //get the address
}
var rprAvmWidgetOptions = {
//this is the var that the rpr widget needs
Token: "742980EF-52EE-46F2-AEFB-B2D29D42AB45",
Query: adress,
CoBrandCode: "btso48",
ShowRprLinks: false
}
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//www.narrpr.com/widgets/avm-widget/widget.ashx/script';
head.appendChild(script);
}
</script>