将FlattenedTreeTableDataSource与CollectionTreeDataSource一起使用时出现问题

时间:2016-07-08 09:35:51

标签: knockout.js requirejs oracle-jet

要求

  1. 带有Pagiantion的表(每个WS调用获取30行)
  2. 行扩展器 - 获取儿童收藏
  3. 儿童 - 无限滚动表
  4. 我打算使用ojTable,oj.Collection,oj.Model oj.PagingTableDataSource< - oj.FlattenedTreeTableDataSource< - oj.FlattenedTreeDataSource< - oj。 CollectionTreeDataSource< - oj.Collection层次结构

    代码

    模型

    define([
        "Model"
    ], function(Model) {
        "use strict";
        var Code = Model.extend({
            "urlRoot": "code",
            "idAttribute": "rowNum",
            "defaults": {
                "rowNum": null,
                "code": null
            }
        });
        return Code;
    });
    

    集合

    define([
        "Collection"
        "../models/Code"
        ], function(Collection, Code){
            "use strict";
            var Codes = Collection.extend({
                url: "code",
                model: Code
            });
            return Codes;
    });
    

    VM代码

    self.codes = new Codes(null, collectionOptions);
    self.treeDataSource = new oj.CollectionTreeDataSource(
            {
                root:self.codes,
                parseMetadata:function(model){
                    var retObj = {};
                    retObj['key'] = model.id;
                    return retObj;
                },
                childCollectionCallback:function(col , model){
                ...
                }
            });
    
    self.treeTableDataSource = new oj.FlattenedTreeTableDataSource(new oj.FlattenedTreeDataSource(self.treeDataSource));
    self.dataSource = new oj.PagingTableDataSource ( self.treeTableDataSource );
    

    HTML

    <table id="table" 
        data-bind="ojComponent: 
        {
            component: 'ojTable', 
            data: dataSource, 
            rowTemplate: 'row_temp', 
            columns:$component.columns
        }">
    </table>
    <div id="paging" data-bind="ojComponent: {component: 'ojPagingControl', data: $component.dataSource, pageSize: 10}">
    </div>
    <script type="text/html" id="row_temp">
        <tr>
          <td>
            <div data-bind="ojComponent: {
                component: 'ojRowExpander', 
                context: $rowContext}"></div>
          </td>
        </tr>
    </script>
    

    问题:

    1)虽然数组大小正确,但ojtable中的数据也是带有键的“未定义”。使用普通的TableDataSource测试了相同的集合并且工作正常。

    ojtable.js:8265 Uncaught (in promise) TypeError: Cannot read property 'toString' of undefined
        at oj.TableDomUtils.hashCode (http://127.0.0.1:8080/js/libs/ojet/oj/v2.0.2/debug/ojtable.js:8265:14)
        at _refreshTableBodyRow (http://127.0.0.1:8080/js/libs/ojet/oj/v2.0.2/debug/ojtable.js:5296:52)
        at ._refreshTableBodyRow (http://127.0.0.1:8080/js/libs/jquery/jqueryui-amd-1.11.4.min/widget.js:4:1032)
        at _refreshTableBody (http://127.0.0.1:8080/js/libs/ojet/oj/v2.0.2/debug/ojtable.js:5256:20)
        at ._refreshTableBody (http://127.0.0.1:8080/js/libs/jquery/jqueryui-amd-1.11.4.min/widget.js:4:1032)
        at _refreshAll (http://127.0.0.1:8080/js/libs/ojet/oj/v2.0.2/debug/ojtable.js:5155:14)
        at ._refreshAll (http://127.0.0.1:8080/js/libs/jquery/jqueryui-amd-1.11.4.min/widget.js:4:1032)
        at .<anonymous> (http://127.0.0.1:8080/js/libs/ojet/oj/v2.0.2/debug/ojtable.js:3826:18)
        at http://127.0.0.1:8080/js/libs/ojet/oj/v2.0.2/debug/ojtable.js:6681:39
    

    2)在这种情况下,我看到偏移没有被分页设置,但在普通表中按预期工作。

    3)我在初始加载时看到多次执行WS调用(获取所有记录,但获取大小为30),因为它应该只获取前30条记录。

    4)oj.CollectionTreeDataSource使用的选项字面值及其所有root / parseMetadata / childCollectionCallback未记录

    球员, 请在这里帮忙。为什么数据未定义且加载时有多个调用而不是pagiantion

    OJET v2.0.2

    我刚刚调试并发现了

    ojcollectiontreedatasource.js

    oj.CollectionNodeSet.prototype.getData = function(index)
    {
        this._checkRange(index);
        return this.collection.at(index).attributes;
    };
    

    返回

    Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
    

    不确定原因?

1 个答案:

答案 0 :(得分:1)

我有同样的问题。经过调试(很多)后,结果发现oj.Model s idAttribute指向一个不存在的字段。

例如:

var CustCollection = new oj.Collection.extend({
    url : 'https://dev.example.com/app/rest/categories',
    model : new oj.Model.extend({
        parse : function __parseSearch(response) {
            console.log(response); // <-- CHECK HERE
            return response;
        },
        idAttribute : 'categoryId' // <-- FIX HERE
    }),
    comparator : 'categoryId' // <-- FIX HERE
});

self.CustColl(new CustCollection());
self.searchDatasource(new oj.CollectionTableDataSource(self.CustColl()));

我这里有一个复制粘贴错误,我忘了更改idAttribute

请检查您的数据源的响应并进行相应的修复。

问题是ojTable没有在当前行上找到键(== idAttribute)列的值,并且没有在那里发脾气,它默默地继续前进,并且由于缺少空检查,我们会收到一个完全不相关的问题的通知。