显示错误 trim 时如何在 react-redux 中捕获数据?

How to catch data in react-redux when error trim is show?

当我没有声明类别时,我无法加载 post,但是如果我尝试设置默认类别,那么我就不能更改另一个类别吗? Somody必须Idea做什么? 使用选择器 - Redux.

 const catchTaxonomies = useSelector(
    state => ({
      catchTaxonomies: state.catchTaxonomies
    })
  );

let taxonomiesEqual =  catchTaxonomies.catchTaxonomies;

正在根据 catchTaxonomies 从 siedbar 发送的类别从 Kentico 下载数据


const fetchArticles = categories => {
    client.items()
      .type("article")
      .containsFilter("elements.categories", [categories])
      .elementsParameter(["title", "image", "urlslug", "headline", "content", "pagination", "categories"])
      .getObservable()
      .subscribe(response => {
        console.log(response.items);
        if(response.pagination.nextPage) {
          setLoadNewArticles(!loadNewArticles);
        }else {
          setLoadNewArticles(false);
        }
        setData(response.items);
        setLoading(!isLoading);
      });
  }

然后我把这个函数给useEffect

useEffect(() => {  
      fetchArticles(taxonomiesEqual);
  }, [])

错误信息:

filters.js:171 Uncaught TypeError: m.trim is not a function at filters.js:171 at Array.map () at ContainsFilter.getParamValue (filters.js:170) at url.helper.js:22 at Array.forEach () at UrlHelper.addOptionsToUrl (url.helper.js:20) at QueryService.BaseDeliveryQueryService.getUrl (base-delivery-> > query.service.js:93) at MultipleItemQuery.BaseQuery.resolveUrlInternal (base-query.class.js:57) at MultipleItemQuery.BaseItemQuery.getMultipleItemsQueryUrl (base-item-query.class.js:93) at MultipleItemQuery.BaseItemQuery.runMultipleItemsQuery (base-item-query.class.js:104) at MultipleItemQuery.getObservable (multiple-item-query.class.js:234) at fetchArticles (Main.js:33) at Main.js:53 at commitHookEffectList (react-dom.development.js:18053) at commitPassiveHookEffects (react-dom.development.js:18080) at HTMLUnknownElement.callCallback (react-dom.development.js:147) at Object.invokeGuardedCallbackDev (react-dom.development.js:196) at invokeGuardedCallback (react-dom.development.js:250) at commitPassiveEffects (react-dom.development.js:19706) at wrapped (scheduler-tracing.development.js:177) at flushPassiveEffects (react-dom.development.js:19759) at renderRoot (react-dom.development.js:20332) at performWorkOnRoot (react-dom.development.js:21357) at performWork (react-dom.development.js:21267) at performSyncWork (react-dom.development.js:21241) at requestWork (react-dom.development.js:21096) at scheduleWork (react-dom.development.js:20909) at scheduleRootUpdate (react-dom.development.js:21604) at updateContainerAtExpirationTime (react-dom.development.js:21630) at updateContainer (react-dom.development.js:21698) at ReactRoot.push../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.development.js:22011) at react-dom.development.js:22163 at unbatchedUpdates (react-dom.development.js:21486) at legacyRenderSubtreeIntoContainer (react-dom.development.js:22159) at Object.render (react-dom.development.js:22234) at Module../src/index.js (index.js:8) at webpack_require (bootstrap:781) at fn (bootstrap:149) at Object.0 (index.js:10) at webpack_require (bootstrap:781) at checkDeferredModules (bootstrap:45) at Array.webpackJsonpCallback [as push] (bootstrap:32) at main.chunk.js:1

您的查询失败,因为 'containsFilter' 的第二个参数包含无效参数。您需要传递一个字符串数组,例如:

.containsFilter('elements.categories', ['category1', 'category2'])

你能仔细检查你在 categories 变量中得到的值吗?