Reputation: 61
I use knockout to render a dynamic list, that has as CSS property width auto ( "width: auto") and I need to know when this CSS is applied. Is there is an event to capture when the CSS styles are applied to the DOM, or an event for the time when the DOM is ready to be visible?
<div style: "width= auto">
<!-- ko foreach: items -->
<div class="list-item" data-bind="css: { active: !$parent.isActive() }">
<a data-bind="text: Label"></a>
</div>
<!-- /ko -->
</div>
thanks
Upvotes: 1
Views: 244
Reputation: 63780
Let me summarize the two already mentioned options, and add two other options as well:
css
binding: Create a custom binding based on the built in css binding that allows for a callback after applying changes. The css
binding is not that big / difficult, so creating a fork/spinoff seems okay to me.afterRender
on the foreach
you can link some code to rendering of individual elements, and adjust the DOM / CSS accordingly.Upvotes: 2
Reputation: 23372
The style attribute (in which you should swap out the =
and the :
symbols) is applied during the first render and will be visible right away.
The css
binding is applied when you call ko.applyBindings
.
If you want to hide stuff until you've applied bindings, you could use a trick like:
<div class="hideUntilBind" data-bind="css: { 'hideUntilBind': false }"></div>
With css:
.hideUntilBind { display: none; }
Upvotes: 2