How do I populate one text-list upon the selection of another text-list?

StackOverflow https://stackoverflow.com/questions/19550372

  •  01-07-2022
  •  | 
  •  

Domanda

I have some JSON data that I'm converting to Rebol blocks using http://reb4.me/r/altjson that looks something like this:

jobs_data: make object! [
    sections: [
        make object! [
            id: "1"
            title: "Section Title 1"
            jobs: [
                make object! [
                    id: "101"
                    title: "Job Title 1"
                    description: {Job description one.}
                ]
            ]
        ]
        make object! [
            id: "2"
            title: "Section Title 2"
            jobs: [
                make object! [
                    id: "201"
                    title: "Job Title 2"
                    description: {Job description two.}
                ]
                make object! [
                    id: "202"
                    title: "Job Title 3"
                    description: {Job description three.}
                ]
            ]
        ]
    ]
]

I'm populating one text-list with all the section titles by doing:

text-list data (map-each section jobs_data/sections [section/title])

I also have a blank text-list below that one. I want to populate that second text list with the job titles of the selected section. How do I go about doing that? I've tried something like this:

REBOL []

do http://reb4.me/r/altjson

jobs_data: load-json %./jobs.json

view layout [
    sections: text-list data (map-each section jobs_data/sections [section/title]) [
        ; How do I get the jobs of the given section?
    ]

    jobs: text-list
]
È stato utile?

Soluzione

Possible solution:

REBOL []

do http://reb4.me/r/altjson

jobs_data: load-json %./jobs.json
currently_selected: copy []

view layout [
    sections: text-list data (map-each section jobs_data/sections [section/title]) [
        currently_selected: pick jobs_data/sections face/cnt
        jobs/data: (map-each job currently_selected/jobs [job/title]) show jobs
    ]

    jobs: text-list
]

I'm not certain that face/cnt is the best way to get the index of the selected list item. Anyone?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top