【发布时间】:2019-03-28 16:23:27
【问题描述】:
我在我的代码中使用了敲除 observables。
我的代码是这样的
self.allAggs = ko.observableArray();
self.aggregatedDataSource = ko.observable( new oj.ArrayTableDataSource(self.allAggs, {idAttribute: 'itemName'}) );
self.aggregatedDataSource.subscribe(function(value) {
console.log('Value changed for aggregatedDataSource');
console.log(ko.toJS(value));
});
插入数据我使用下面的代码
self.allAggs(newdata);
我有两个问题:
- 作为 newdata 的一部分传递给 self.allAggs 的数据与 UI 上显示的数据不同。
HTML 代码如下所示:
<div id="aggregationContainer" data-bind="visible: isVisibleContainer($element.id)" class="blk" style="display:none;">
<table id="aggTable" class="amc-full-width-table amc-max-height-table"
data-bind="ojComponent: {component: 'ojTable',
data: aggregatedDataSource,
display: 'grid',
columnsDefault: {sortable: 'enabled'}, columns: [
{headerText: $data.l10n_default('desktop-management.toolbar.option.',$data.selectedReportType()), field: 'itemName'},
{headerText: oj.Translations.getTranslatedString('desktop-management.report.column.hostCount'), renderer: hostCountRenderer, sortProperty: 'hostCount'}],
rootAttributes: {class:'amc-full-width-table'},
sort: $data.onVersionTableSort}">
</table>
</div>
- 控件从不进入订阅函数。
请帮助我了解我在哪里做错或遗漏了什么。
【问题讨论】:
-
ArrayTableDataSource实例被一个 observable 包裹,但不能改变这个 observable。使用新数据设置allAggs将触发对allAggs的订阅,并可能触发ArrayTableDataSource的属性(我无法确定,因为您尚未共享其来源)。 -
1.这是一个 oracle-jet 问题。这个标签很重要。 2. 作为 newdata 的一部分传递给 self.allAggs 的数据与 UI 上显示的不同。 - 如果是这样,那么请向我们展示“预期”与“实际”的结果。 3. Observables 监控它自己的值的变化,而不是它里面的任何东西。它类似于如果您有一个可观察的对象数组,并且您更改其中一个对象的属性,则不会向订阅者发送更改事件
-
另外请说明您使用的 oracle-jet 版本
标签: knockout.js observable oracle-jet knockout-subscribe