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>
4

1 に答える 1

1
self.tasks(resp);

既存の監視可能な配列に新しい値を設定する必要があります

于 2013-04-12T15:02:18.033 に答える