1

I thought the mapping plugin should return an observable array but the obbservable array is empty even though 'resp' response from server has 1000s of elements.

Am I missing something here? Please see below.

 <script type="text/javascript">         

        function tasksViewModel() {
            var self = this;

            self.tasks = ko.observableArray(null);

            self.load = function () {
                $.ajax({
                    url: '/api/benchmark',              
                    success: function(resp) {
                       // This line isn't working!
                       self.tasks = ko.mapping.fromJS(resp);
                    },
                    dataType: 'json'
                });
            }
        }

        var viewModel = new tasksViewModel();

        $(function () {

            ko.applyBindings(viewModel);
            viewModel.load();
        });

    </script>

1 Answer 1

1
self.tasks(resp);

you should set new value to existed observable array

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I remember now. The mapping creates observables of single properties not arrays, thanks. Wish this was a little more clear on their site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.