我想将数据从ajax推送到淘汰的observableArray,但这给了我一个错误:


  初始化可观察数组时传递的参数必须是
  数组,或者为null,或者为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);
        }

    });
});

最佳答案

据我所知,这条线应该改变。

 state = ko.observableArray([]);


对此

var state = ko.observableArray();

07-25 23:11
查看更多