I want to push data from ajax to knockout observableArray , but it give me an error:
The argument passed when initializing an observable array must be an array, or null, or undefined.
efine(['uiComponent', 'ko', 'jquery'], function (Component, ko, jquery) {
return Component.extend({
initialize: function () {
this._super();
/* State and cities */
this.selectCity();
},
selectCity: function () {
var myViewModel = {};
state = ko.observableArray([]);
jquery.ajax({
url: 'http://127.0.0.1/magento/hamechio/region.php',
type: "GET",
dataType: "json",
success: function(data) {
myViewModel = data;
state.push(data);
}
});
console.log(state);
}
});
});