Question

My View Model is :

function MyInfo(data) {
        this.line = ko.observable(data);

    }
function MyViewModel() {
            var self = this;
            self.Plines = ko.observableArray([]);

            $.getJSON("URL",
            function (allData) {
                 var mappedData = $.map(allData, function (item) { return new MyInfo(item) });
            self.Plines = mappedData;
            });
            alert(self.Plines);

        }

        ko.applyBindings(new MyViewModel());

And View does just have a Select.

<select data-bind="options: Plines,  optionsText: ''"></select>

The JSON response I have is:

["Item1","Item2","Item3","Item4","Item5"]
Was it helpful?

Solution

change self.Plines = allData; to self.Plines(allData);

Also, change:

<select data-bind="options: Plines,  optionsText: ''"></select>

to

<select data-bind="options: Plines,  optionsText: 'line'"></select>

here's a working example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top