javascript - knockout.js not mapping observable array from json -


can't map json observable array. use code tutorial (http://learn.knockoutjs.com/).

function movie(data) {     this.name = ko.observable(data.name);     this.description = ko.observable(data.description);     this.duration = ko.observable(data.duration);     this.id = ko.observable(data.id);     this.imdb_id = ko.observable(data.imdb_id);     this.original_name = ko.observable(data.original_name);     this.poster = ko.observable(data.poster);     this.type = ko.observable(data.type);     this.year = ko.observable(data.year); }  function movielistviewmodel() {     // data     var self = this;      self.moviesarray = ko.observablearray([]);     self.searchquery = ko.observable();      self.searchmovies = function () {         $.getjson("/api/v1/movies/search/", {"query": self.searchquery }, function(alldata) {             var mappedmovies = $.map(alldata.movies, function(item) { return new movie(item) });             console.log(mappedmovies); // in line output: [movie, movie, movie, movie, movie, movie]              self.moviesarray(mappedmovies);             console.log(self.moviesarray); // in line output: []         });         }; }  ko.applybindings(new movielistviewmodel()); 

i not understand wrong.

p.s. sorry english

this

{"query": self.searchquery } 

should be

{"query": self.searchquery() } 

this

console.log(self.moviesarray) 

should be

console.log(self.moviesarray()) 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -