【发布时间】:2017-08-08 09:33:41
【问题描述】:
我想从 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 数组时,它可以工作 任何帮助表示赞赏。
【问题讨论】:
-
你得到什么错误?
taches是对象数组,还是只是对象? -
taches 只是对象
-
如果
taches是一个对象,那么调用$.each是没有意义的。你必须做self.data.push({ title: taches.type, releaseYear: taches.levels, director: taches.title });。如果这是实际修复,您的控制台中应该有一条错误消息... -
@user3297291 非常感谢它的工作
标签: javascript arrays json object jet