I have a Each element like this:
<Each Items="{MyItem}">
<Panel>
<Text Value="{Text}"/>
<Clicked Handler="{WhatId}" />
</Panel>
</Each>
And in Js I have:
function MyItem(Text,Id){
this.Text = Text;
this.Id = Id;
}
function WhatId(){
}
How can Access in Js to the Id of the clicked Each (MyItem)?
Thanks!
Hi! Hopefully this example makes it clear how to access the context of the clicked item:
<App Theme="Basic">
<StackPanel>
<JavaScript>
var Observable = require('FuseJS/Observable');
var selectedItemName = Observable('None selected')
function selectItem(args) {
console.log (JSON.stringify(args));
selectedItemName.value = args.data.name
}
module.exports = {
items : [
{name: "item1"},
{name: "item2"},
{name: "item3"}
],
selectedItemName: selectedItemName,
selectItem: selectItem,
}
</JavaScript>
<Text Value="{selectedItemName}" />
<Each Items="{items}">
<Panel Clicked="{selectItem}">
<Text Value="{name}" />
</Panel>
</Each>
</StackPanel>
</App>
The console.log
-statement will list the available properties on the clicked arguments:
{"data":{"name":"item1"},"x":53,"y":36,"index":0}
{"data":{"name":"item2"},"x":25,"y":48,"index":0}
{"data":{"name":"item3"},"x":27,"y":68,"index":0}