I have a simple collection bound to an observableArray that is initially empty. When the page renders it 'sometimes' will show the empty template before the binding kicks in and removes the element. If you can't see it refresh the page a few times. This is happening as below with the container less templates but also happens with normal inline and script tag style templates.
View:
<div>
<input data-bind="value: address"/>
<button data-bind="click: search">Search</button>
</div>
<!-- ko if: list().length > 0 -->
<h5 data-bind="text: list().length"></h5>
<!-- /ko -->
<!-- ko foreach: list -->
<div class="result" data-bind="text: addr"></div>
<!-- /ko -->
Javascript:
$(function() {
var viewModel = function() {
var self = this;
self.address = ko.observable("Portland");
self.list = ko.observableArray();
self.hasData = function(){return self.list().length > 0;};
self.search = function() {
self.list.push({ addr: "Item01" , index: 1 });
self.list.push({ addr: "Item02" , index: 2 });
self.list.push({ addr: "Item03" , index: 3 });
};
};
var vm = new viewModel();
ko.applyBindings(vm);
});
I doesn't seem to happen to much on jsFiddle - http://jsfiddle.net/motowilliams/mx7SM/ or JSBin but does happen locally and when deployed - http://knockouttest.herokuapp.com/.
Any ideas?