Hello,
I have a question about catching args.data inside Component on Tapped/Clicked.
Background:
I want to show a list of news from Observable in NewsItem
component. The NewsItem
component compose of title, content, and share button. The NewsItem
doesn’t have any properties.
If I click on the news wrapper then it executes clickWrapper
function, and if I click on share news then it will execute shareNews
function then get the title and content.
However, when I log the output of those function, I always get an empty object.
Screenshots
Output:
Below is the output when I click the NewsItem
component of “News 1”, and click the share button of “News 3”
[Viewport]: click wrapper
[Viewport]: {"title":"News Title 1","content":"This is content of news 1"}
[Viewport]: ------
[Viewport]: share news
[Viewport]: {}
[Viewport]: click wrapper
[Viewport]: {"title":"News Title 3","content":"This is content of news 3"}
[Viewport]: ------
Question:
How can I get the args.data of the component when I click the share button?
Is anyone know how to solve this problem?
My Files
MainView.ux
<App>
<JavaScript>
var Observable=require('FuseJS/Observable');
var news = Observable([]);
news.replaceAll([
{ title: 'News Title 1', content: 'This is content of news 1' },
{ title: 'News Title 2' , content: 'This is content of news 2' },
{ title: 'News Title 3' , content: 'This is content of news 3' },
{ title: 'News Title 4', content: 'This is content of news 4' }]);
module.exports = {
news: news
};
</JavaScript>
<StackPanel Margin="0,50">
<Each Items="{news}">
<NewsItem />
</Each>
</StackPanel>
</App>
NewsItem.ux
<Panel ux:Class="NewsItem" Color="#eaeaea" Margin="10,5">
<JavaScript>
clickWrapper = (args) => {
console.log('click wrapper', JSON.stringify(args.data));
console.log('------');
}
openNews = (args) => {
console.log('open news', JSON.stringify(args.data));
}
shareNews = (args) => {
console.log('share news', JSON.stringify(args.data));
}
module.exports = {
clickWrapper,
openNews,
shareNews
}
</JavaScript>
<Tapped>
<Callback Handler="{clickWrapper}"></Callback>
</Tapped>
<StackPanel Padding="10">
<StackPanel>
<Tapped>
<Callback Handler="{openNews}"></Callback>
</Tapped>
<Text Value="{title}" />
<Text Value="{content}" FontSize="14" />
</StackPanel>
<Text TextAlignment="Right" FontSize="12" Color="Red" Value="Share">
<Tapped>
<Callback Handler="{shareNews}"></Callback>
</Tapped>
</Text>
</StackPanel>
</Panel>