私は、ドラフトjsでcontentEditorを構築しようとしています。厳密にはFacebookのようなURLからデータを抽出する機能です。しかし、私はこの部分に立ち往生しています。コールバックが機能していません。ajaxリクエストでコールバックが機能していませんか?
まず私は、私はこれが基本的なJavaScriptの問題であるかわからない ...コールバックが動作しない場合、コンポーネントは表示されませんcompositeDecorator
constructor(props) {
super(props);
const compositeDecorator = new CompositeDecorator([
.... {
strategy: linkStrategy,
component: decorateComponentWithProps(linkComp, {
passit
})
}
....
]);
}
// This is my strategy
function linkStrategy(contentBlock, callback, contentState) {
findLinkInText(LINK_REGEX, contentBlock, callback)
}
function findLinkInText(regex, contentBlock, callback) {
const text = contentBlock.getText();
let matchArr, start;
if ((matchArr = regex.exec(text)) !== null) {
start = matchArr.index;
let URL = matchArr[0];
console.log(URL);
axios.post('/url', {
url: URL
}).then(response => {
passit = response.data
//not working
callback(start, start + URL.length)
})
//working
callback(start, start + URL.length)
}
}
と私の状態を包みました。しかし、私は自分のサーバーからURLデータを取得したいので、データをプロップ経由でコンポーネントに渡してコンポーネントに渡してレンダリングする必要があります。他のすべてが動作していると仮定すると、ANSWER
function findLinkInText(regex, contentBlock, callback) {
const text = contentBlock.getText();
let matchArr, start;
if ((matchArr = regex.exec(text)) !== null) {
start = matchArr.index;
let url = matchArr[0];
axios.post('/url', {
url: URL
}).then(response => {
passit = response.data
handleWithAxiosCallBack(start, start + matchArr[0].length, callback)
}).catch(err => console.log(err))
}
}
function handleWithAxiosCallBack(start, startLength, callback) {
console.log(callback); //Spits out the function But Not working
callback(start, startLength)
}
私の例では、 'linkStrategy'にコールバックを渡す方法はありません。 'Strategy:linkStrategy'の詳細を投稿してください。 –
Sir、LinkStrategyからコールバックを他のfuntionに渡しています。コールバックが実行されるコールバックが見つかります。@ MaximShoustin – Nane
@Nane - あなたのpassit変数に' passit = response。データ 'である。 'console.log'で確認できますか? –