V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
particlec
0.01D
V2EX  ›  问与答

代码中数组自己变成了对象为什么?

  •  
  •   particlec · Aug 1, 2022 · 1346 views
    This topic created in 1368 days ago, the information mentioned may be changed or developed.
    const createTerm = () => {
    form
    .validateFields()
    .then((value) => {
    console.log(value.aliases);
    let api =
    termInfo && Object.hasOwn(termInfo, "id")
    ? glossaryApi.updateGlossary({ ...value, id: termInfo?.id })
    : glossaryApi.createGlossary({ ...value, domainId: 1000 });
    api
    .then((res) => {
    setTermReturnId(res?.data);
    message.success("术语创建成功");
    })
    .catch(() => {
    message.error("术语创建失败");
    });
    })
    };

    console.log(value.aliases);打印结果是
     ['近似值 1', '近似值 2']

    接口调用时,参数是
    aliases: {0: "近似值 1", 1: "近似值 2"}

    这就很奇怪
    3 replies    2022-08-02 10:45:53 +08:00
    maichael
        1
    maichael  
       Aug 1, 2022
    请求体里面显示的也是 aliases: {0: "近似值 1", 1: "近似值 2"} ?
    particlec
        2
    particlec  
    OP
       Aug 2, 2022
    jifengg
        3
    jifengg  
       Aug 2, 2022
    { ...value, domainId: 1000 }

    兄弟,你解构后又重构一个 object ,可不就这样了么
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2643 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 03:15 · PVG 11:15 · LAX 20:15 · JFK 23:15
    ♥ Do have faith in what you're doing.