I'm working on a Windows 8 App in HTML5/Javascript. I created a custom control that uses a stack of DIVs to display content, and each DIV is rendered using WinJS.Binding.Template. The setup is close to the answer in this question: WinJS.UI.ListView customize list item content? .
The binding data is close to:
[
{
"title": "title name",
"allow_action": false
"action_type": "go"
},
...
]
And my template is close to:
<div id="entry" data-win-control="WinJS.Binding.Template">
<div data-win-bind="textContent: title">
</div>
<a class="action">Action</a>
</div>
Upon binding, I would like to:
- Change the
classNameofa.actionbased on the value ofallow_actionandaction_type. - Attach an event (
addEventListener) toa.actionupon binding, based on the contents of the binding data. This includesallow_action,action_typeand other values.
Basically, I wish to have a pre-binding or post-binding callback function, with the element, and bind data as arguments. This doesn't appear to be possible with converters because converter doesn't let you access other fields.
Meanwhile I'm manually processing these things with DOM after render. I'm wondering if there are better options available. Thank you.
Update
As suggested by @GotDibbs and @RSW in the comments, I managed to solve problem #1 using the solution from Sending multiple parameters to WinJS.Binding.converter() function . I'm wondering if #2 is still possible?
thisinstead of specific property, you can access your entire model from the converter. Also, there is no pre-bind or post-bind callback function that I'm aware of short of the promise returned from WinJS.Binding.processAll(). You may need to look into having the CSS class name and the event handler right on the object you're binding. - GotDibbsthisagain, and use a converter to redirect it to the actual handler you want to use? - GotDibbs