Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentFragment not Append to Dom #127

Closed
cqh963852 opened this issue Sep 24, 2023 · 1 comment
Closed

DocumentFragment not Append to Dom #127

cqh963852 opened this issue Sep 24, 2023 · 1 comment

Comments

@cqh963852
Copy link
Contributor

cqh963852 commented Sep 24, 2023

I am creating a todo list

const items = van.state<number[]>([1,2,3]);
let count = 3;

van.add(
  document.getElementById("app")!,
  van.tags.button(
    {
      onclick: () => {
        items.val = [...items.oldVal, count++];
      },
    },
    "add item",
    () => items.val.length,
  ),
 // todo list here
  () => {
    const parent = document.createDocumentFragment();

    items.val.forEach((item) => {
      const element = van.tags.div(item);
      parent?.append(element);
    });

    return parent;
  },
);

I want the todo items append to the app div. without a wrapper. So I tried DocumentFragment

This todo list will only be executed once and will not be executed a second time due to changes in items. May I ask why this is?

@Tao-VanJS
Copy link
Member

Tao-VanJS commented Sep 24, 2023

DocumentFragment is different from passthrough container element. Once you inserted a DocumentFragment object into the DOM tree, the fragment object itself will not be inserted into the tree. Its children will be inserted instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants