I am looking for an explaination, why my example works only whit the document ready handler inside the for-loop
:
Here Iam trying to append/remove some rows:
ko.bindingHandlers.customControl = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext)
{
var value = valueAccessor();
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext)
{
var value = valueAccessor();
var unmapped = value();
var $element = $(element);
$(function ()
{
$element.find("bla").remove();
for (i = 0; i < 10; i++)
{
$element.find("table tbody").append('<tr class="bla">some text</tr>');
}
});
}
};
Our c# helper method looks kind of:
@helper CustomTableControl(string dynamicBindArray)
{
//...defining some lists
<div data-bind="customControl : @dynamicBindArray">
<table class="table customTable">
<thead>
<tr>
@foreach (string item in Listitem)
{
<th>@item</th>
}
</tr>
</thead>
<tbody data-bind="foreach: @dynamicBindArray">
<tr data-bind="visible: ...">
@for (int i = 0; i < properties.Count; i++)
{
<td>
<span data-bind="text: @properties[i]"></span>
</td>
}
</tr>
</tbody>
</table>
</div>
}
And in the .csthml
-file I call it like this:
@helper.CustomTableControl("SomeKoObservableArray")
Actually it does not make sense to call the document ready handler every time in the for-loop
... right ?!
Its something like this post. Thanks.