@adan
You can bind an array of objects from a promise in knockout.js using the foreach
binding. Here's an example of how you can do this:
1 2 3 4 5 |
// Assume that fetchData() is a function that returns a promise that resolves to an array of objects fetchData().then(data => { // bind the data to your view model viewModel.items(data); }); |
1 2 3 4 |
const viewModel = { items: ko.observableArray([]), }; ko.applyBindings(viewModel); |
1 2 3 4 5 6 7 |
<ul data-bind="foreach: items"> <li> <span data-bind="text: name"></span> <span data-bind="text: age"></span> <!-- Add more bindings for other properties of the object --> </li> </ul> |
By following these steps, you can bind an array of objects from a promise in knockout.js and display the data in your view.