【问题标题】:Receive object datatype from back4app in react在反应中从 back4app 接收对象数据类型
【发布时间】:2022-01-19 07:45:21
【问题描述】:

我在“过期”1 列中从 back4app 中的数据库接收数据类型对象时遇到问题。我对接收其他数据类型(字符串、数组..)没有任何问题,但我无法将对象解构为日、月和年。

我有以下代码接收其他数据类型并将其保存在 useState 中:

const [ideaTable, setIdeaTable] = useState();

  async function fetchIdeas() {
    const query = new Parse.Query("Idea");
    try {
      const ideas = await query.find();
      console.log("Parse Objects: ", ideas);
      const destructuredIdeas = destructureIdeas(ideas);
      setIdeaTable(destructuredIdeas);
      console.log("from readIdeas: ", ideaTable);
      return true;
    } catch (error) {
      alert(`Error ${error.message}`);
      return false;
    }
  }

  function destructure(idea) {
    return {
      id: idea.id,
      title: idea.get("title"),
      section: idea.get("tags"),
      author: idea.get("author"),
/*        expiration: JSON.stringify(idea.get("expiration")) */
      expiration: idea.get("expiration")
       
    };
  }

  function destructureIdeas(ideas) {
    return ideas.map(destructure);
  }

Here I just call: "expiration: idea.get("expiration")" as in above code.所以,我想我需要重新构造过期对象以获取日、月和年......但是如何?

如果我这样做:"expiration: JSON.stringify(idea.get("expiration"))",我会得到以下结果3

那么,如果我想显示例如:“14.12.2021”怎么办?

【问题讨论】:

    标签: reactjs object get datagrid back4app


    【解决方案1】:

    我自己找到了答案:

    expiration: idea.get("expiration").day
    expiration: idea.get("expiration").month
    expiration: idea.get("expiration").month
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-29
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 1970-01-01
      相关资源
      最近更新 更多