继续获取ReferenceError:未定义fter

时间:2017-10-27 16:21:09

标签: referenceerror

我的过滤器函数发送了我想要在我的filter.sql中使用的两个参数,但无济于事,它总是返回这个。在某些时候,我无法弄清楚我的参数没有到达控制器文件。它是在发送到端点之前定义的,但是当它试图在控制器函数中使用该值时,它没有定义。

第一个过滤功能:

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());
 }

前端控制台上的错误是

 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)

这里发生了什么?我在其他地方遇到过这个问题,但我现在不能忽视它。我必须解决它,但它不符合!!

感谢您的时间!!!!!

1 个答案:

答案 0 :(得分:0)

我不确定,也许您需要更改为以下内容? :

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

因为我觉得此时fterfText还没有被定义,但是filterfilterText是你可能想要使用的它们。