Hi!
As I have mentioned in a previous post, I’m creating an application for voting, and I’ve run into some problems:
I have elements representing score from 1 through 5. But Right now it seems I need 5 clickhandlers - one for each element. So this leaves me with 5 functions doing pretty much the same. In HTML there’s functionality for adding custom data using the data-attribute, could it be possible to do the same here and have them as a part of the parameters in the clickhandler?
To me this would look something like this:
<JavaScript>
function voteHandler(args) {
console.log(args.data.score);
}
module.exports = {
voteHandler: voteHandler
}
</JavaScript>
<StackPanel>
<Panel data-score="5" Click="{voteHandler}">
<Text Value="Vote 5!" />
</Panel>
<Panel data-score="4" Click="{voteHandler}">
<Text Value="Vote 4!" />
</Panel>
<Panel data-score="3" Click="{voteHandler}">
<Text Value="Vote 3!" />
</Panel>
<Panel data-score="2" Click="{voteHandler}">
<Text Value="Vote 2!" />
</Panel>
<Panel data-score="2" Click="{voteHandler}">
<Text Value="Vote 2!" />
</Panel>
<Panel data-score="1" Click="{voteHandler}">
<Text Value="Vote 1!" />
</Panel>
</StackPanel>
Really open for other ways to solve it, but to me this feels a lot better than having multiple event-handlers for basicly the same thing.
Also, is there possible for the UI to know if a callback returns true or false? Let’s consider the function from above that would do an ajax-call to a backend storing the vote. If the vote is saved, it returns true, anything else it returns false. Let’s say I’d like the vote-button become red if it fails, and green if it’s successful. How would I go ahead and do this?
As the elements people would use to vote is generated dynamicly, I guess an observable would make the whole UI react the same, as I would need each element to react separatly.
Regards JoMs