• ARعربي
  • ENEnglish
  • ESEspañol
  • FAفارسی
  • FRFrançais
  • IDIndonesia
  • ITItaliano
  • JA日本語
  • KO한국어
  • RUРусский
  • TRTürkçe
  • UKУкраїнська
  • ZH简体中文

ما قصد داریم این پروژهٔ متن‌باز را در دسترس همهٔ مردم در سرتاسر دنیا قرار دهیم.

به ترجمهٔ محتوای این آموزش به زبان خودتان کمک کنید/a>.

    نقشه آموزش
    اشتراک گذاری
    • آموزش
    • مرورگر: Document، Eventها، رابط‌ها
    • Document
    • Modifying the document
    بازگشت به درس
    این محتوا تنها در این زبان‌ها موجود است: English, Español, Français, Italiano, 日本語, 한국어, Русский, Türkçe, Українська, 简体中文. لطفاً به ما

    Create a tree from the object

    اهمیت: 5

    Write a function createTree that creates a nested ul/li list from the nested object.

    For instance:

    let data = {
      "Fish": {
        "trout": {},
        "salmon": {}
      },
    
      "Tree": {
        "Huge": {
          "sequoia": {},
          "oak": {}
        },
        "Flowering": {
          "apple tree": {},
          "magnolia": {}
        }
      }
    };

    The syntax:

    let container = document.getElementById('container');
    createTree(container, data); // creates the tree in the container

    The result (tree) should look like this:

    Choose one of two ways of solving this task:

    1. Create the HTML for the tree and then assign to container.innerHTML.
    2. Create tree nodes and append with DOM methods.

    Would be great if you could do both.

    P.S. The tree should not have “extra” elements like empty <ul></ul> for the leaves.

    باز کردن یک sandbox برای تمرین.

    The easiest way to walk the object is to use recursion.

    1. The solution with innerHTML.
    2. The solution with DOM.
    • © 2007—2025  Ilya Kantor
    • دربارهٔ پروژه
    • تماس با ما