There are lots of ways! Depends on what kind of data you really need. For instance, if you can track down your item
instance using the name (or other identifying info), you could do something like this:
<template repeat="{{item in items}}">
<div on-click="{{addme}}" data-item-name="{{item.name}}" layout horizontal justified>
<div>{{item.name}}</div>
<core-icon icon="settings"></core-icon>
</div>
</template>
Then in the event handler:
addme(event, details, target){
String name = target.dataset['item-name'];
// then find your item instance using "name"
}
Or you could create a custom element for your items, maybe <item-view>
, and repeat those.
<template repeat="{{item in items}}">
<item-view item="{{item}}"></item-view>
</template>
That makes it even easier and cleaner to get at the item
instance you want, because target
will have a public property containing the reference. Let me know if you'd like to see a more thorough example of that approach.
And you can even do it with enumeration, which would allow you to get the index within the repeat
, and that same index could be used to look up the item
instance in the original List
(assuming it's a List
you're repeating over). That looks like this:
<template repeat="{{item in items | enumerate}}">
<div on-click="{{addme}}" data-index="{{item.index}}" layout horizontal justified>
<div>{{item.value.name}}</div>
<core-icon icon="settings"></core-icon>
</div>
</template>
You can get the index inside addme()
like:
int index = int.parse(target.dataset['index']);
Confused yet? Always so many ways to do things, eh?