2017-10-27 10 views
0

私のfilter関数は、filter.sqlで使用したい2つのパラメータを送信しますが、常に返すことはありません。ある時点で、私のパラメータがコントローラファイルに到達しないことがわかりません。エンドポイントに送信される前に定義されていますが、コントローラー関数でその値を使用しようとすると、定義されていません。ReferenceError:fterが定義されていません

第一のフィルタ機能:

handleFilter() { 
console.log(this.state.filter); 
console.log(this.state.filterText); 
if (this.props.searchText === "") { 
    axios 
    .post("/api/filter", { fText: this.state.filterText, fter: 
this.state.filter }) 
    .then(response => { 
     this.props.updateCSR(response.data); 
     updateFPO(this.props.filterPopout === false ? true : false); 
    }); 
} else { 
    axios 
    .post(
    "/api/sfilter", 
    { 
     fText: this.state.filterText, 
     fter: this.state.filter, 
     sText: this.props.searchText 
    } 
    ) 
    .then(response => { 
     this.props.updateCSR(response.data); 
     updateFPO(this.props.filterPopout === false ? true : false); 
    }); 
    } 
    } 

エンドポイント

app.post("/api/filter", ic.filter); 
app.post("/api/sfilter", ic.sfilter); 

コントローラにおいてフィルタ:

filter: (req, res, next) => { 
const { filter, filterText } = req.body; 
const dbInstance = req.app.get("db"); 
dbInstance 
    .filter([fter, fText]) 
    .then(resp => { 
    res.status(200).send(resp); 
    }) 
    .catch(() => res.status(500).send()); 
}, 
sfilter: (req, res, next) => { 
const { fter, fText, sText } = req.body; 
const dbInstance = req.app.get("db"); 
dbInstance 
    .sfilter([fter, fText, sText]) 
    .then(resp => { 
    res.status(200).send(resp); 
    }) 
    .catch(() => res.status(500).send()); 
} 

ERRフロントエンドのコンソールには

POST http://localhost:3000/api/filter 500 (Internal Server Error) 
dispatchXhrRequest @ xhr.js:178 
xhrAdapter @ xhr.js:12 
dispatchRequest @ dispatchRequest.js:52 
Promise resolved (async) 
request @ Axios.js:58 
Axios.(anonymous function) @ Axios.js:78 
wrap @ bind.js:9 
handleFilter @ Filter.js:33 
onClick @ Filter.js:79 
callCallback @ react-dom.development.js:1299 
invokeGuardedCallbackDev @ react-dom.development.js:1338 
invokeGuardedCallback @ react-dom.development.js:1195 
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:1209 
executeDispatch @ react-dom.development.js:1432 
executeDispatchesInOrder @ react-dom.development.js:1454 
executeDispatchesAndRelease @ react-dom.development.js:1969 
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:1980 
forEachAccumulated @ react-dom.development.js:1946 
processEventQueue @ react-dom.development.js:2139 
runEventQueueInBatch @ react-dom.development.js:2151 
handleTopLevel @ react-dom.development.js:2161 
handleTopLevelImpl @ react-dom.development.js:1800 
batchedUpdates @ react-dom.development.js:13238 
performFiberBatchedUpdates @ react-dom.development.js:1646 
stackBatchedUpdates @ react-dom.development.js:1637 
batchedUpdates @ react-dom.development.js:1651 
batchedUpdatesWithControlledComponents @ react-dom.development.js:1664 
dispatchEvent @ react-dom.development.js:1874 
createError.js:16 Uncaught (in promise) Error: Request failed with status code 500 
    at createError (createError.js:16) 
    at settle (settle.js:18) 
    at XMLHttpRequest.handleLoad (xhr.js:77) 

ここでは何が起こっていますか?私は他の場所でこの問題を抱えていましたが、今は無視できません。私はそれを修正する必要がありますが、それは準拠していません!

ありがとうございました!!!!!

答えて

0

私はよく分かりませんが、次のように変更する必要がありますか? :

dbInstance 
    .filter([filter, filterText]) 
    .then(resp => { 
    res.status(200).send(resp); 
    }) 
    .catch(() => res.status(500).send()); 
}, 

その時点でfterfTextがまだ定義されていませんが、filterfilterTextがそのように、あなたはおそらくそれらを使用することを意図しているように、それは私には見えますので。

+0

私はあなたが言っていることを見ています。私はこれを変更しました。 (私はこれを以前に変更したと思った)。それはまだ壊れています。 :(私は私のメッセージを更新しているというエラーを受け取ります。それを含めるのを忘れました。 –

関連する問題