1

I am generating the following in a for loop (ignore the jade template syntax for now):

ul.nav.nav-tabs(data-bind="foreach: channels", id="galery_tabs") li a(data-toggle='tab', data-bind="attr: {href: '#tab_section_' + __kb.object.cid},html: name() + ' <i class=\"icon-remove close\" data-binding=\"click: removeChannel\"></i>'") 

When I call .applyBindings it will correctly render my A element with the Icon that has a binding inside.

Question: How do I make second pass apply to ensure the dynamically generated binding is now applied to all Icon elements as well?

3
  • man, we can't ignore that jade template syntax.. please, put a good HTML code Commented Jun 3, 2014 at 18:06
  • Why are you using the html binding here? Why don't you just put the <i> inside your <a>? Commented Jun 3, 2014 at 19:45
  • Im using html binding because i dynamically merge content the Name of that "tab" plus the "x" icon that needs to remove the tab. if I put the icon outside of the a it screws up the tab content. maybe i should solve it that way lol. Commented Jun 3, 2014 at 20:14

1 Answer 1

1

You don't need to use the html binding for the scenario.

You can just put your <i> inside the <a> and you can use the KO container-less syntax to add the name property before the icon:

ul.nav.nav-tabs(data-bind="foreach: channels", id="galery_tabs") li a(data-toggle='tab', data-bind="attr: {href: '#tab_section_' + __kb.object.cid}") // ko text: name // /ko i.icon-remove.close(data-binding="click: removeChannel") 

And the generated HTML will look like this:

<ul data-bind="foreach: channels" id="galery_tabs" class="nav nav-tabs"> <li><a data-toggle="tab" data-bind="attr: {href: '#tab_section_' + __kb.object.cid}"> <!-- ko text: name --> <!-- /ko--><i data-binding="click: removeChannel" class="icon-remove close"></i></a></li> </ul> 
Sign up to request clarification or add additional context in comments.

1 Comment

Whaoaaa.. buddy you're my hero. Solution worked like charm. \m/. kudos! Never considered containerless bindings.. awesome!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.