gpt4 book ai didi

javascript - 如何将 React 组件连接到 Quickbooks 按钮

转载 作者:搜寻专家 更新时间:2023-11-01 05:28:30 24 4
gpt4 key购买 nike

我正在尝试将 Quickbooks 按钮 ( https://developer.intuit.com/docs/0100_quickbooks_online/0100_essentials/000500_authentication_and_authorization/widgets#/Connect_to_QuickBooks_button ) 连接到 React 组件中,并且我正在尝试复制以下方法:Adding script tag to React/JSX .

Quickbooks 按钮使用以下脚本代码:

<script
type="text/javascript"
src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere-1.3.3.js">
</script>
<script src="https://js.appcenter.intuit.com/Content/IA/intuit.ipp.anywhere-1.3.3.js" type="text/javascript"></script>
<script type="text/javascript">
intuit.ipp.anywhere.setup({
grantUrl: 'http://www.mycompany.com/HelloWorld/RequestTokenServlet',
datasources: {
quickbooks : true,
payments : true
},
paymentOptions:{
intuitReferred : true
}
});
</script>
<body>
<ipp:connectToIntuit></ipp:connectToIntuit>
</body>

我尝试使用以下 React 代码,但它不起作用。任何帮助表示赞赏。谢谢。

import React from 'react';

class ConnectToQuickBooksOnlineButton extends React.Component {
constructor(props){
super(props);
this.state = {
};
}

componentWillMount() {
const library = document.createElement("script");
library.src = "https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere-1.3.3.js";
library.type = "text/javascript"
library.async = true;
document.body.appendChild(library);

const setup = document.createElement("script");
setup.src = "https://js.appcenter.intuit.com/Content/IA/intuit.ipp.anywhere-1.3.3.js";
setup.type = "text/javascript";
setup.async = true;
document.body.appendChild(setup);

const connect = document.createElement("script");
connect.type = "text/javascript";
connect.innerHTML = "intuit.ipp.anywhere.setup({grantUrl: '/quickbooksauth',datasources: {quickbooks : true, payments : true}, paymentOptions:{intuitReferred : true}});"
document.body.appendChild(connect);

const body = document.createElement("body");
body.innerHTML = "<ipp:connectToIntuit></ipp:connectToIntuit>";
body.async = true;
document.body.appendChild(body);
}

render(){
return <div />;
}
};

export default ConnectToQuickBooksOnlineButton;

我尝试将脚本内容放在 index.html 中,然后从 Quickbooks 组件中调用它。但是按钮仍然没有显示。

import React from 'react';

class ConnectToQuickBooksOnlineButton extends React.Component {
constructor(props){
super(props);
this.state = {
};
}

componentWillMount() {
const connectToIntuit = document.createElement('ipp:connectToIntuit');
document.body.appendChild(connectToIntuit);
}

render(){
return <div ref="ipp:connectToIntuit"/>;
}
};

export default ConnectToQuickBooksOnlineButton;

我还创建了以下 fiddle :https://jsfiddle.net/aewhatley/7eL716mp/

最佳答案

@alex 看起来您正在尝试在渲染之前访问 Dom,您应该使用“componentDidMount”将您的直觉按钮加载到 div 或容器上。

我创建了一个 WebpackBin 来说明实现,如果这就是你想要实现的原因,请告诉我?

这是我创建的简单组件

QuickBooks.js

工作演示 WebpackBin https://www.webpackbin.com/bins/-Kg6yu5JUmy9dD08JI_A

import React from 'react'

class QuickBooks extends React.Component {
constructor(props){
super(props);

window.intuit.ipp.anywhere.setup({
grantUrl: 'http://www.mycompany.com/HelloWorld/RequestTokenServlet',
datasources: {
quickbooks : true,
payments : true
},
paymentOptions:{
intuitReferred : true
}
})

}
componentDidMount() {
let buttonContainer = document.getElementById("intuButton")
const connectToIntuit = document.createElement('ipp:connectToIntuit');
buttonContainer.appendChild(connectToIntuit);
}
render(){
return (
<div id="intuButton"></div>
)
}
}

export default QuickBooks
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.0/react-dom.min.js"></script>

关于javascript - 如何将 React 组件连接到 Quickbooks 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42942413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com