With the following knockout.js code, I’d like to set a flag within an inner loop and then use the flag outside of the loop. What’s the best way to do this?
<!-- there is an ASP.NET outer loop here -->
<!-- initialize variable 'myFlag = true' here -->
<div data-bind="foreach: jobs">
<!-- ko if: industry == 'tech' -->
<!-- set myFlag to false here -->
<!-- display job info here -->
<!-- /ko -->
<!-- ko if: myFlag == true -->
<!-- display 'no jobs for industry' message here -->
<!-- /ko -->
</div>
<!-- end outer ASP.NET outer loop -->
You can try the afterRender property of the foreach binding:
This will call doSomething for each iteration of jobs.