Skip to content

Element.replaceChildren(node1, node2, node3, ...nodes) / how to use Function.apply ? #292

Open
@jonasfj

Description

@jonasfj

In JS we can do:

containerForValues.replaceChildren(...values.map((value) => {
  const element = document.createElement('div');
  element.innerHTML = value;
  return element;
}));

In Dart we I tried using:

containerForValues.replaceChildren(
  values
      .map(
        (value) => HTMLDivElement()
          ..setHTMLUnsafe(value),
      )
      .toList()
      .toJS,
);

But this doesn't work, because the first argument can't be a list. So the list is converted to a String. Do my containerForValues ends up showing:

[object HTMLDivElement],[object HTMLDivElement],[object HTMLDivElement]

:D

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions