javascript - Kendo UI HierarchicalDataSource for Treeview with dynamic schema -


i'm trying display kendo treeview hierarchicaldatasource. it's simple region, country, city hierarchy difficulty comes fact have 3 possible levels of regions , countries can appear @ second or @ third level.

basically, - first level of regions contains other regions - second level of regions contains other regions or countries - third level of regions contains countries

here schemas:

 var portsschema = {             schema: {                 data: "portlist",                 model: {                     id: "code"                 }             }         };          var countryschema = {             schema: {                 data: "countrylist",                 model: {                     id: "code",                     children: portsschema                 }             }         };          var regioncountryschema = {             schema: {                 data: "regionlist",                 model: {                     id: "id",                     children: countryschema                 }             }         };          var regionschema = {             schema: {                 data: "regionlist",                 model: {                     id: "id",                     children: regioncountryschema                 }             }         }; 

depending on fact region has countries or not, specify specific type of children (regionschema or regioncountryschema).

var tvdatasource = new kendo.data.hierarchicaldatasource({             data: regions,             schema: {                 model: function (data) {                      **how return right children schema ?**                 }             }         }); 

returning { children: regionschema } or {children: regioncountryschema } triggers js kendo error.

any idea achieve ? thank you. json data sample below.

[    {      "id": 1,      "name": "middle east , red sea",      "regionlist": [        {          "id": 12,          "name": "middle east",          "regionlist": [            {              "id": 45,              "name": "m. east",              "regionlist": [                              ],              "countrylist": [                {                  "id": 12007,                  "code": "ae",                  "name": "uae",                  "portlist": [                    {                      "id": 6005,                      "code": "aejea",                      "name": "jebel ali"                    },                    {                      "id": 16014,                      "code": "aeajm",                      "name": "ajman"                    },                    {                      "id": 16015,                      "code": "aeauh",                      "name": "abu dhabi"                    },                    {                      "id": 15109,                      "code": "aeklf",                      "name": "khor al fakkan"                    },                    {                      "id": 15001,                      "code": "aerkt",                      "name": "ras al khaimah"                    },                    {                      "id": 16018,                      "code": "aeshj",                      "name": "sharjah"                    },                    {                      "id": 14863,                      "code": "aeqiw",                      "name": "umm al qaiwain"                    },                    {                      "id": 15647,                      "code": "aefjr",                      "name": "al - fujayrah"                    }                  ]                },                {                  "id": 12018,                  "code": "om",                  "name": "oman",                  "portlist": [                    {                      "id": 6011,                      "code": "omsll",                      "name": "salalah"                    },                    {                      "id": 16218,                      "code": "omsoh",                      "name": "sohar"                    }                  ]                },                {                  "id": 10069,                  "code": "bh",                  "name": "bahrain",                  "portlist": [                    {                      "id": 15345,                      "code": "bhkbs",                      "name": "bahrain"                    }                  ]                },                {                  "id": 62292,                  "code": "iq",                  "name": "iraq",                  "portlist": [                    {                      "id": 15383,                      "code": "iqbsr",                      "name": "basra"                    },                    {                      "id": 14673,                      "code": "iquqr",                      "name": "umm qasr pt"                    }                  ]                },                {                  "id": 62291,                  "code": "ir",                  "name": "iran, islamic republic of",                  "portlist": [                    {                      "id": 15250,                      "code": "irbkm",                      "name": "bandar khomeini"                    },                    {                      "id": 15249,                      "code": "irbnd",                      "name": "bandar abbas"                    },                    {                      "id": 14973,                      "code": "irbuz",                      "name": "bushehr"                    },                    {                      "id": 14671,                      "code": "irkho",                      "name": "khorramshahr"                    }                  ]                },                {                  "id": 62306,                  "code": "kw",                  "name": "kuwait",                  "portlist": [                    {                      "id": 15810,                      "code": "kwsaa",                      "name": "shuaiba"                    },                    {                      "id": 15811,                      "code": "kwswk",                      "name": "shuwaikh"                    }                  ]                },                {                  "id": 12002,                  "code": "sa",                  "name": "saudi arabia",                  "portlist": [                    {                      "id": 15039,                      "code": "sajub",                      "name": "jubail"                    },                    {                      "id": 16147,                      "code": "sadmm",                      "name": "ad dammam"                    }                  ]                },                {                  "id": 62364,                  "code": "qa",                  "name": "qatar",                  "portlist": [                    {                      "id": 15739,                      "code": "qadoh",                      "name": "doha"                    },                    {                      "id": 14795,                      "code": "qames",                      "name": "mesaieed"                    }                  ]                }              ]            }          ],          "countrylist": [                      ]        },        {          "id": 30,          "name": "red sea",          "regionlist": [            {              "id": 65,              "name": "red sea",              "regionlist": [                              ],              "countrylist": [                              ]            }          ],          "countrylist": [            {              "id": 12002,              "code": "sa",              "name": "saudi arabia",              "portlist": [                {                  "id": 6003,                  "code": "sakac",                  "name": "king abdullah port"                },                {                  "id": 15731,                  "code": "sajed",                  "name": "jeddah"                }              ]            },            {              "id": 10114,              "code": "dj",              "name": "djibouti",              "portlist": [                {                  "id": 8059,                  "code": "djjib",                  "name": "djibouti"                }              ]            },            {              "id": 10122,              "code": "er",              "name": "eritrea",              "portlist": [                {                  "id": 15031,                  "code": "ermsw",                  "name": "massawa"                }              ]            },            {              "id": 62300,              "code": "jo",              "name": "jordan",              "portlist": [                {                  "id": 14801,                  "code": "joaqj",                  "name": "al \u0027aqabah"                }              ]            },            {              "id": 50001,              "code": "sd",              "name": "sd",              "portlist": [                {                  "id": 15734,                  "code": "sdpzu",                  "name": "port sudan"                }              ]            },            {              "id": 62425,              "code": "ye",              "name": "yemen",              "portlist": [                {                  "id": 15302,                  "code": "yehod",                  "name": "hodeidah"                },                {                  "id": 15304,                  "code": "yemkx",                  "name": "mukalla"                },                {                  "id": 15300,                  "code": "yeade",                  "name": "aden"                }              ]            },            {              "id": 10118,              "code": "eg",              "name": "egypt",              "portlist": [                {                  "id": 16030,                  "code": "egsok",                  "name": "sokhna port"                }              ]            }          ]        }      ],      "countrylist": [              ]    }  ]


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -