I’ve setup a StackPanel with Items coming from a javascript array. There is a TextInput on top where new items can be added. This works fine: when adding an item, the view also updates.
The issue is where I want to update a title from a single item in the list. For the method addTag()
I would expect the item title to update to ‘New Title’ if the button within that item is clicked. The array on the javascript part seems to be updating but not the view.
My javascript is as following:
DealNotifier.js
class DealNotifier {
constructor() {
this.title = '';
this.items = [];
}
addItem(e) {
this.items.push({
title: this.title,
tags: []
});
this.title = '';
}
addTag(props) {
this.items = this.items.map((item, index) => {
if (index == props.index) {
console.log('setting item'); // this actually logs to the console
item.title = 'New Title';
}
return item
});
}
}
And this is the UX:
<App Model="DealNotifier">
<ClientPanel Background="#EEF0F2">
<DockPanel>
<DockPanel Dock="Top">
<TextInput Value={title} PlaceholderText="Give a title.." Background="#ccc" />
<Button Text="Add watcher" Dock="Right" Tapped={addItem} />
</DockPanel>
<ScrollView>
<StackPanel>
<Each Items={items}>
<StackPanel>
<Rectangle CornerRadius="10" Color="#EEC643" Margin="2,5,2,0" Padding="10, 20">
<StackPanel>
<Text Value={title} FontSize="15" TextColor="#fff" />
<!-- tags -->
<StackPanel Orientation="Horizontal">
<Each Items={tags}>
<Text Value={} />
</Each>
</StackPanel>
<DockPanel>
<TextInput PlaceholderText="Add some tags.." />
<Button Text="Add" Clicked={addTag} Dock="Right" Color="#000" />
</DockPanel>
<!-- /tags -->
</StackPanel>
</Rectangle>
</StackPanel>
</Each>
</StackPanel>
</ScrollView>
</DockPanel>
</ClientPanel>
</App>