Knockoutjs afterRender is not firing on native template
-
25-05-2021 - |
Pregunta
Consider some HTML markup which uses MVC partial view to create a dialog. When selectedMember is set on the viewmodel, the dialog will be populated and the openDialog event gets called which calls Jquery dialog("open").
I use the afterRender event to ensure unobtrusive validation works since the dialog is dynamically created. However the afterRender function is never called?
<div id="dlgAddMember" class="hidden" data-bind="with: selectedMember, openDialog: selectedMember, afterRender:hookupValidation">
@Html.Action(ekmMvc.People.AddMemberDialog())
</div>
Does anyone know why this isn't working. It seems this was working ok using Jquery template engine.
Solución
You need to specify it like:
data-bind="template: { data: selectedMember, if: selectedMember, afterRender: hookupValidation }"
When you do not specify a name for the template, then it will use anonymous templates. So, this is the equivalent of with
with an afterRender.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow