Working with Knockout 'foreach' looping through multidimensional array

前端 未结 3 1006
粉色の甜心
粉色の甜心 2021-01-13 12:59

I have a multidimensional associative array.

this.items = ko.observableArray([
    { name: \"name1\", viewable: true, children: [
        { name: \"name1-1\"         


        
3条回答
  •  失恋的感觉
    2021-01-13 13:54

    Underscore.js has some nice method working with arrays maybe you can use flatten and filter to create one array from your structure then you can just write one foreach:

    Or you could use templates to encapsulate your if: viewable logic and apply the template recursively:

    
    
    

    Demo JSFiddle.

提交回复
热议问题