Handling items inside items

Hi,

i have a problem while creating items inside an item:

<Each Items="{vItems}">
    <StackPanel>
      <Text Value="{name}"/>
      <StackPanel Margin="20">        
          <Each Items="{innerItem}">       
                <Text Value="{innerName}"/>       
          </Each>  
      </StackPanel>
    </StackPanel>
    </Each>

if i try to do it all at once it works without any problem:

vItem = Observable();
vItem.add({name: "value1", innerItem: Observable({innerName: "1"}, {innerName: "2"})});

but i have 2 questions:

  • How to add the inner items after creating the parent one?

what i tried and didn’t work:

vItem = Observable();
vItem.add({name: "value1", innerItem: Observable()});

//something like:
vItem.value[0].innerItem.add({innerName: "1"});
vItem.value[0].innerItem.add({innerName: "2"});

  • How to add the inner values as a JSON?

what i tried and didn’t work:

var jsonText = '{innerName: "1"},{innerName: "2"}';
vItem.add({name: "value1", innerItem: Observable(JSON.parse(jsonText))});

answer to 1st question is:

vItem.value.getAt(0).innerItem.add({innerName: "1"});

but still not knowing how to solve 2nd

Hi!

First of all your json must be properly formed, you are missing array brackets []

Second, this is how you add an array to an observable item by item:

innerItem.addRange(some_array);

Hope this helps :slight_smile:

thnx!

i already tried with and without brackets… the part i was missing was the “addRange”