viewof Object

Is it possible to create a view of an object? Something along the lines of:

viewof foo.bar = html`<input type=text placeholder="foo">`

The above returns RuntimeError: viewof foo is not defined

Yes, a view’s value can be an object. However, you must define the view in a single cell rather than defining each property in a separate cell. Here’s an example that uses a generic form element:

Alternatively, if you want to define your inputs in separate cells, you could flatten your object into multiple views:

viewof fooBar = …

And you could then also reconstitute these views into a single object if desired:

foo = ({bar: fooBar})
2 Likes