I’m pushing strings onto an observableArray and I’d like to use the ‘foreach’ binding with a <ul></ul> element. The <li></li> items are just the strings.
I can’t seem to see how I go about doing this. It seems the example I’ve seen shows the <li> items are referencing items inside js objects pushed onto a stack and so bind to the property of the object.
I’ve tried $data but that doesn’t work either.
e.g.
<ul data-bind="foreach: vm.errors()">
<li data-bind="text: ?"></li>
</ul>
// after json response...
$.each(response.data, function(key, errorMessage) {
vm.errors.push(errorMessage);
});
You can use
$datato refer to the current data at that scope level, so you can dodata-bind="text: $data"