【问题标题】:Keep getting ReferenceError: fter is not defined不断收到 ReferenceError:未定义过滤器
【发布时间】:2017-10-27 16:21:09
【问题描述】:

我的过滤器函数发送了我想在我的 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)

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

感谢您的宝贵时间!!!!!!

【问题讨论】:

    标签: referenceerror


    【解决方案1】:

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

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

    因为在我看来 fterfText 尚未定义,但 filterfilterText 是你可能打算使用它们。

    【讨论】:

    • 我明白你在说什么。我改变了这个。 (我以为我早些时候改变了这个)。它仍然坏了。 :( 我收到更新消息的错误。我忘了包括那个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    相关资源
    最近更新 更多