billpull / knockout-bootstrap

A plugin that adds custom bindings for twitter bootstrap objects such as tooltips and popovers.
232 stars 69 forks source link

Pass data through popover trigger #4

Closed mika76 closed 11 years ago

mika76 commented 11 years ago

Would it be possible to pass a bound object through the trigger to the template?

Something like:

<button class="btn" 
   data-bind="popover: {template: 'popoverBindingTemplate', 
   title: 'Oh Yea Binding', 
   value:someObject}">
Launch Binding Popover
</button>

<script type="text/html" id="popoverBindingTemplate">
<button class="close pull-right" type="button" data-dismiss="popover">×</button>
<form>
<label>Property</label>
<input type="text" data-bind="value: SomePropertyOfObject, valueUpdate:'afterkeydown'" />
</form>
</script>
billpull commented 11 years ago

It depends on how your view model is setup on the page you should be able to reference children of an object inside the popover without passing in any additional parameters. It would be great if you could attempt what you want to accomplish with the current plugin in a JS fiddle and I can have a better idea of what limitation you are running into.

mika76 commented 11 years ago

I'll get back to you with a fiddle, but to be more clear, imagine showing details, in a popup, of an item that is in a foreach list.

billpull commented 11 years ago

That should be possible I would suggest using something like foreach: {data: items, as: 'item'} in your loop. I created this fiddle to demonstrate http://jsfiddle.net/K4uMh/ let me know if I am missing something.

mika76 commented 11 years ago

Man that's great - I didn't know about "as". Thanks!