question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need help with selectors from array

See original GitHub issue

I have all my data in an object. I have 3 dropdowns, and I each dropdown to populate based on the selection of the previous one.

For example:

data = {
  "campaign1": {
    "name": "Campaign 1",
    "projects": {
      "job A": [
        "proj 1"
      ],
      "job B": [
        "proj 2",
        "proj 3"
      ]
    }
  },
  "campaign2": {
    "name": "Campaign 2",
    "projects": {
      "job C": [
        "proj 4",
        "proj 5",
        "proj 6"
      ],
      "job D": [
        "proj 7",
        "proj 8",
        "proj 9"
      ]
    }
  }
}

The idea is that first you choose a “Campaign”, then 2nd dropdown shows “Jobs” for that campaign, then 3rd shows “Projects” for that job.

This is what I’ve tried for the first 2 items, but I’m not understanding how watch, enumSource, and template work together:

var editor = new JSONEditor(document.getElementById("editor"), {
...
  schema: {
    type: "object",
    properties: {
      campaign: {
        id: "campaign",
        type: "string",
        enumSource: [{
          source: Object.entries(data),
          value: "{{item.0}}",
          title: "{{item.1.name}}"
        }],
      },
      project: {
        type: "string",
        watch: { "c": "campaign" },
        enumSource: [{
          source: Object.entries(data),
          title: "{{item[c].projects}}"
        }]
        ....

The first item shows the campaigns correctly, but how do I then use that selection to populate the 2nd dropdown?

Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13

github_iconTop GitHub Comments

2reactions
schmunk42commented, Mar 4, 2019

btw, I just ran cloc against Alpaca’s src

 schmunk@xps-15  ~/Workspace/_tmp/alpaca-master  
> cloc src            
     176 text files.
     163 unique files.                                          
      16 files ignored.

github.com/AlDanial/cloc v 1.80  T=0.11 s (1426.0 files/s, 339515.6 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JavaScript                      90           4696           8489          22655
HTML                            67            342             21           1120
CSS                              5            281            139            828
-------------------------------------------------------------------------------
SUM:                           162           5319           8649          24603
-------------------------------------------------------------------------------

and json-editor

 schmunk@xps-15  ~/Workspace/json-editor/json-editor   master  
> cloc src          
      59 text files.
      59 unique files.                              
       0 files ignored.

github.com/AlDanial/cloc v 1.80  T=0.04 s (1441.0 files/s, 263157.6 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
JavaScript                      58           1089            933           8710
CSS                              1              0              0             43
-------------------------------------------------------------------------------
SUM:                            59           1089            933           8753
-------------------------------------------------------------------------------
1reaction
pmk65commented, Mar 4, 2019

Watching a field from within the schema is rather limited, compared to watching the field from JavaScript. If you watch the field(s) from JavaScript, you can manipulate the fields better. Take a look at this example: https://github.com/json-editor/json-editor/wiki/Adding-autoprefilling-based-on-value-in-another-field-using-Bloodhound

Read more comments on GitHub >

github_iconTop Results From Across the Web

array-selector – API Reference - Polymer Project
Custom element that links paths between an input `items` array and an output `selected` item or array based on calls to its selection...
Read more >
javascript - Selectors-based search through an array of elements
I have a pre-selected list of Node objects, and I want a function that could take the same selectors parameter, but search inside...
Read more >
DOM Selectors and Their Array-Like Objects | by Kelly M.
Before we dive into the selectors themselves, it is crucial that we understand what they give back to us are not arrays, but...
Read more >
Document.querySelectorAll() - Web APIs | MDN
A non-live NodeList containing one Element object for each element that matches at least one of the specified selectors or an empty NodeList...
Read more >
[Solved] Selectors As Arrays - Help with OR-groups
You'll need to use the "verbose" version of a selector array. Ryan gives an example of a verbose selector array this in this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found