【问题标题】:React onClick listItem display the data of selected listItem from JSONReact onClick listItem 显示 JSON 中所选 listItem 的数据
【发布时间】:2018-09-04 01:14:29
【问题描述】:

我是编码世界的新手。学习 react 和 json。我正在研究三个连接在一起的不同面板。我想在第三个面板上显示清单答案。

第一个面板:
显示:所有 esn ("4667","4668")
onclick 第一个 esn:"4667" 它应该在第二个面板上显示 esn:"4667" 的所有 gmtdatetime。
第二个面板:
显示:esn的所有gmtdatetime:"4667" ('2018-08-31 03:22:16','2018-08-30 03:12:16')
onclick 第一个 gmtdatetime '2018-08-31 03:22:16' 它应该在该 gmtdatetime '2018-08-31 03:22:16' 的第三个面板上显示问题 + 答案。
第三面板:
它应该以这种格式显示第一个 gmtdatetime 的所有值(问题+答案)。我想显示是或否,而不是真或假。
问题解答
问题 1 真 == “是”
问题 2 真 == “是”
问题 3 错误 ==“否”
问题 4 真 == “是”

原码:react-editor

输出

  onClick on ESN ("4667") =>
                          onClick Date & Time ("2018-08-31 03:22:16") =>  
                                               Checklist (Question + Answer)
                                              "question 1"  true == "YES"
                                              "question 2"  true == "YES"
                                              "question 3"  false == "NO"
                                              "question 4"  true == "NO"


我的 json 数据看起来像这样

    [
    {
        esn: '4667',
        completed_checklists: [
            {
                gmtdatetime: '2018-08-31 03:22:16',
                answers: ['true','true','false','true']
            },
            {
                gmtdatetime: '2018-08-30 03:12:16',
                answers: ['false','true','true','true']
            }
        ],
        question: ['question 1','question 2','question 3','question 4']
    },
    {
        esn: '4668',
        completed_checklists: [
            {
                gmtdatetime: '2017-08-31 03:22:16',
                answers: ['true','false','false','true']
            },
            {
                gmtdatetime: '2017-08-31 03:23:16',
                answers: ['true','false','false','true']
            }
        ],
        question: ['question 1','question 2','question 3','question 4']

    },

]

问题 获取第二个面板和第三个面板上的所有数据。

谢谢

【问题讨论】:

    标签: javascript arrays json reactjs


    【解决方案1】:

    你好,我已经 fork 你的代码,我想这就是你在here之后的样子

    【讨论】:

    • 非常感谢。我有一个关于答案的问题。如何更改显示 True == "YES" False == "NO"。我想显示 yes 和 no 而不是 true 或 false
    • @contactdummy 查看下面的答案
    • @GuillermoQuiros 你还在惠灵顿吗?不错!
    • 是的,我在下雨又下雨:)
    【解决方案2】:

    这个答案显示了一个完整的解决方案,带有true == YESfalse == NO

    https://stackblitz.com/edit/react-wej2w1

    【讨论】:

    • 谢谢你,但我想输出这样的东西onClick on ESN ("4667") => onClick Date & Time ("2018-08-31 03:22:16") => Checklist (Question + Answer) "question 1" true == "YES" "question 2" true == "YES" "question 3" false == "NO" "question 4" true == "NO"'
    • Guillermo 代码工作完美,只是如何将 true 更改为 yes 并将 false 更改为 no..
    • 嗨@contactdummy,请参阅我的答案中的更新链接
    • 我同意 - 这将非常有用。我会试着找时间:-)
    • link 你能帮我解决这个问题吗?这是反应传单。
    猜你喜欢
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-19
    • 2017-08-31
    相关资源
    最近更新 更多