I saw here similar questions discussing the end of specific element bindings, usually aferRender
is proposed to use, but what about whole page bindings done event? Is there any? I need to run some jQuery code which just does not work in parallel with bindings.
Asked
Active
Viewed 1,566 times
1

YMC
- 4,925
- 7
- 53
- 83
1 Answers
1
ko.applyBindings()
is a blocking call.
Why not simply execute your jQuery code after you execute ko.applyBindings()
?

Jim G.
- 15,141
- 22
- 103
- 166
-
Technically It might be a way out, but in my case it's a separate file (separate partial view in mvc terms) where jQuery code suppose to be located with its own separate logic, while ko.applyBindings() is in the other main page, and I would not like them to be a loosely coupled as possible. – YMC Sep 07 '12 at 19:46
-
@YMC: Putting javascript in a view is an anti-pattern.http://weblogs.asp.net/dwahlin/archive/2011/10/31/techniques-strategies-and-patterns-for-structuring-javascript-code.aspx – Jim G. Sep 07 '12 at 19:50
-
I read the article but honestly I did not get why it is anti-pattern to put javascript code right into the page. As I understand it just says that if you have a bunch of javascript code it's more maintainable to organize it into nested closures, I don have clunky code, it's few lines of code. – YMC Sep 07 '12 at 20:14
-
@YMC: Did you see this snippet? *Most people (including myself) start out writing JavaScript code by adding function after function into a .js or HTML file. While there’s certainly nothing wrong with that approach since it gets the job done, it can quickly get out of control when working with a lot of code. When lumping functions into a file, finding code can be difficult, refactoring code is a huge chore (unless you have a nice tool like Resharper 6.0), variable scope can become an issue, and performing maintenance on the code can be a nightmare especially if you didn’t originally write it.* – Jim G. Sep 07 '12 at 20:15
-
@YMC: Your code may not be clunky right now, but it's likely that it will be extended later, perhaps by developers other than yourself, and that's when it can become a maintenance nightmare. // Also, javascript code is much more *readable* when it exists by itself in its own file. – Jim G. Sep 07 '12 at 20:17
-
Ok, but does it change anything in the initial question? Let say I'll have separate javascript class to handle the local partial view logic which I do not wanna mix with main page logic, and I want main page where applyBindings() is located does not know who and when to run. How can I catch post-binding even in the case? – YMC Sep 07 '12 at 20:27
-
@YMC: At some level, the components need to know about each other. Have you looked at this answer? http://stackoverflow.com/a/7342861/109941 – Jim G. Sep 07 '12 at 20:36
-
It's not separate ajax call in my case, single data model and one-time applyBindings() call. I just hoped there is some special event provided by KO to bind to, informing about bindings done like $(document).ready in jQuery, if is not, I have to restructure my code anyway – YMC Sep 07 '12 at 21:11