【发布时间】:2018-10-17 10:02:52
【问题描述】:
更新
我相信我发现了错误。我更改了 JSON 数据,发现我设法在 HTML 的最后一个 HeaderText 行上添加了一个“,”。删除它,现在它正在将数据正确推送到表中..
我正在尝试用一些 JSON 数据填充一个表,但我得到的只是这个错误:
Uncaught Error: oj-table with id 'table1': Unable to parse columns='[
{headerText: "ID", field: "id"},
{headerText: "Name", field: "name"},
{headerText: "Username", field: "username"},
{headerText: "E-mail", field: "email"},
]' for OJ-TABLE with id table1 to a JSON Object. Check the value for correct JSON syntax, e.g. double quoted strings. SyntaxError: Unexpected token h in JSON at position 19
at Object._throwError (ojcustomelement.js:514)
at _coerceVal (ojcustomelement.js:1110)
at Object.oj.BaseCustomElementBridge.__ParseAttrValue (ojcustomelement.js:1124)
at Object.oj.BaseCustomElementBridge.__InitProperties (ojcustomelement.js:1028)
at Object.InitializeElement (ojcomponentcore.js:5504)
at Object._connected (ojcustomelement.js:378)
at HTMLElement._connectedCallback [as connectedCallback] (ojcustomelement.js:404)
at Object.setDomNodeChildren (knockout-3.4.2.debug.js:288)
at Object.setDomNodeChildren (knockout-3.4.2.debug.js:2827)
at Object.oj.CompositeTemplateRenderer.renderTemplate (ojcomposite-knockout.js:105)
我使用https://jsonplaceholder.typicode.com/users 作为我的 JSON 源。 我想将数据推送到指定的列中。我错过了什么?我在 Google 上找到的内容与我的代码非常相似,而且文档对我帮助不大。
我想指出,我是 JET 的新手,之前我没有太多使用 JSON 数据。
我的代码如下所示
HTML
<oj-table id='table1' aria-label='testTable'
data='[[dataSource]]'
columns='[
{headerText: "ID", field: "id"},
{headerText: "Name", field: "name"},
{headerText: "Username", field: "username"},
{headerText: "E-mail", field: "email"},
]'
style='width: 50%;'>
JS
define(
['ojs/ojcore', 'knockout', 'jquery', 'ojs/ojtable', 'ojs/ojarraytabledatasource'],
function (oj, ko, $) {
function testTable() {
var self = this;
self.data = ko.observableArray();
$.getJSON("https://jsonplaceholder.typicode.com/users").
then(function (users) {
$.each(users, function() {
self.data.push({
id: this.id,
name: this.name,
username: this.username,
email: this.email
});
});
});
self.dataSource = new oj.ArrayTableDataSource(
self.data,
{idAttribute: 'id'}
);
}
return testTable;
});
【问题讨论】:
标签: html knockout.js oracle-jet