2d array with collection/model


#1

Hi,

I’m trying to create a 2d array with collection/model(-s) and was wondering what a good practice for that could be.

Let’s say I have a’Job’ with : who, where and what tools they’ll use.

What tools can be [axe, hammer, nails… etc]

What would be a good way to populate this as well as read/manage this data?

Thanks in advance!


#2

Hey!
Based on your description I would create two collections: one containing the Jobs, and one containing the tools.

Ex:
Jobs (Static Data component in JSON)

[
    {
        name: "Construction",
        who: "James",
        where: "1st street",
        tools: [
            {
                id: "HammerTool"
            },
            {
                id: "NailsTool"
            },
            {
                id: "SawTool"
            }
        ]
    },
    {
        //next job here
    }
]

Tools (Static Data component in JSON)

[
    {
        id: "HammerTool",
        name: "Hammer",
        imgPath: "/images/tools/hammer.png",
    },
    {
        //next tool here
    }
]

Another path is to do it all with the javascript collection/model apis.

Let me know if you need a functional example.


#3

Thanks! I’d really appreciate that. I keep on messing something up with the static data node…
Also, is there a way to do that without a JS node? I mean only using the built in collection and model nodes?

Tack!


#4

I feel like I have it done with nodes alone. Still, a code example would be good for posterity!

What I have in this proof of concept is:

  1. A way to create a tool (bottom of window)
  2. The tool gets added to a list of ‘available tools’ for selection (the list on top of window, blue rectangles)
  3. As I tap on any of the tools they get added to a collection ‘tools for job’ with the tool’s ID
  4. The collection of tools is stored in the Job model as the ‘tools’ item (just the collection ID since that’s what I need for reference).

Seems like it works OK. Now just need to find a way of how to manage all these collections upon collections with their ID’s :smiley:


#5


#6

added some colors to selecting/deselecting. If anyone would like to give it a go: https://drive.google.com/drive/folders/18kJT5BJdbE6330Z9pBLQAZjxi1ZgFcks?usp=sharing

Only one job at the moment to add tools to though :slight_smile:


#7

I made a quick example starting with Static Data nodes. One button to add new jobs with specific tools referenced. I only used javascript nodes to create new jobs, it should be doable to do that part with regular components. But the js way is imo easier to overview (and faster to throw together! :wink: ).

Referencing collection within collection.zip (3.6 KB)