将数据从 json 对象推送到 ko.obsrvablearray()

Pushing data from json object to ko.obsrvablearray()

我想从 json 看起来像

的对象中推送一些字段
{
  "type": "tasks",
  "levels": 3,
  "links":    [
        {
            ....
        }   

     ],
     "assignedDate": "2017-08-02 16:03:36",
     "number": 200612,
     "priority": 3,
     "createdDate": "2017-08-02 16:03:36",
     "state": "ASSIGNED",
     "ownerRole": "LoanApplication.Process Owner",
     "processName": "LoanProcess",
     .
     .
     .

}

ko.observableArray。这是我的 JS 代码(我正在使用 oracle jet)

define(['ojs/ojcore', 'knockout', 'ojs/ojtable'], function (oj, ko) {
    function homeContentViewModel() {
    var self = this;
    self.data = ko.observableArray();
    $.getJSON("http://localhost:8085/get/bpm").
            then(function (taches) {
                $.each(taches, function () {
                    self.data.push({
                        title: this.type,
                        releaseYear: this.levels,
                        director: this.title
                    });
                });
            });




    self.dataSource = new oj.ArrayTableDataSource(
            self.data, 
            {idAttribute: 'title'}
    );
    }
    return homeContentViewModel;
   });

ps:当我将 JSON 对象更改为 JSON 数组时,它起作用了 感谢任何帮助。

function Model(opt_data) {
    var data        = opt_data || {};
    var self        = this;
    self.taches     = ko.observableArray([]); // with ([])

    for (var i = 0; i < data.taches.length; i++) {
        var tache = new Tache(data.taches[i]);
        self.taches.push(tache);
    }
}

function Tache(opt_data) { 
    var data = opt_data || {};
    var self = this;

    self.title       = ko.observable(data.type   || "");
    self.releaseYear = ko.observable(data.levels || "");
    self.director    = ko.observable(data.title  || "");
}

var vm = new Model(dataJson); //Your json with some data
ko.applyBindings(vm);

感谢@user3297291 这个成功了

define(['ojs/ojcore', 'knockout', 'ojs/ojtable'], function (oj, ko) {
function homeContentViewModel() {
var self = this;
self.data = ko.observableArray();
$.getJSON("http://localhost:8085/get/bpm").
        then(function (taches) {

                self.data.push({
                    title: this.type,
                    releaseYear: this.levels,
                    director: this.title
                    });
        });




self.dataSource = new oj.ArrayTableDataSource(
        self.data, 
        {idAttribute: 'title'}
   );
   }
   return homeContentViewModel;
});