Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My actual data.d contents:
- {"d":[{"ID":1,"Name":"Justin"},{"ID":2,"Name":"Bob"}]}
- my actual JavaScript:
- var ViewModel = function () {
- var self = this;
- self.items = ko.mapping.fromJS([]);
- self.refresh = function () {
- $.ajax({
- type: "POST",
- url: "Default.aspx/GetProducts",
- data: "{}",
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (data) {
- ko.mapping.fromJS(data.d, self.items);
- }
- });
- };
- }
- var viewModel = new ViewModel();
- $(function () {
- ko.applyBindings(viewModel);
- viewModel.refresh();
- });
- my actual HTML
- <table data-bind="visible:items.length > 0">
- <thead>
- <tr>
- <th>ID</th>
- <th>Name</th>
- </tr>
- </thead>
- <tbody data-bind="foreach: items">
- <tr>
- <td data-bind="text:ID"></td>
- <td data-bind="text:Name"></td>
- </tr>
- </tbody>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement