如何为从非REST服务加载数据的Dojo树实现延迟加载?

时间:2018-07-04 14:02:34

标签: javascript dojo lazy-loading

我已经尝试了一段时间来使懒惰处理与Dojo 1.10(客户要求)树一起工作,但是我一直无法使其工作。数据源是非REST的,或者我将使用JsonRestStore或类似的数据。

我尝试了以下几种不同的在线方式(like thisthisthisthis),但是每种方式都会导致通用的Dojo错误,该错误会通过各种方式跟踪只会引发错误的Dojo基本文件。

我尝试创建一个从ItemFileReadStore / Tree / ForestTreeModel继承的商店/树/模型(并试图劫持它如何获取其数据),但我最接近已经覆盖了ForestTreeModel中的getChildren: function (parentItem, callback, onError)以获取项目并通过商店的_getItemsFromLoadedData函数传递它们,但是在传递时在Uncaught Error: sherpa.LazyLoadTreeReadStore: Invalid item argument.的ItemFileReadStore中给出了_assertIsItem _getItemsFromLoadedData放入模型的callback函数中的结果。

不幸的是,我不能显示太多代码或已加载的数据(机密性协议,但是我可以在下面看到),但是有人可以告诉我我有多少白痴,然后说“这很简单”。 , 或者其他的东西?就像,是否有一个地方可以覆盖“提取”以发布到我需要的服务,然后将数据传递出去?

这是我到目前为止尝试过的:

var getChildren = function (parentItem, callback, onError) {
    var children = scanStructure(treeStructure, parentItem);
    var data = {
        items: children,
        label: getNodeLabel(children[0])
    };
    this.store._getItemsFromLoadedData(data);
    callback(data.items);
    return;
};

require(["custom/LazyLoadTree", "custom/LazyLoadTreeReadStore", "dojo/domReady!"],
function (LazyLoadTree, LazyLoadTreeReadStore) {
    var store = new LazyLoadTreeReadStore({
        structure: treeStructure,
        url: "[...]"
    });

    var myTree = new LazyLoadTree({
        store: store,
        label: "Inputs"
    }, "treePSI");
    myTree.model.getChildren = getChildren;
    myTree.startup();
});

此外,当我尝试使用ForestStoreModel默认值getChildren(如下)时,它表示会产生Uncaught Error: declare dijit.tree.ForestStoreModel: can't deduce a name to call inherited()错误。

if(parentItem === this.root){
    if(this.root.children){
        // already loaded, just return
        callback(this.root.children);
    }else{
        //   !!!  this isn't how it should fetch, I need to change this
        //        but my attempt involved the same code from "getChildren" above
        this.store.fetch({
            query: this.query,
            onComplete: lang.hitch(this, function(items){
                this.root.children = items;
                callback(items);
            }),
            onError: onError
        });
    }
}else{
    this.inherited(arguments);
}

我在这里很机智...有人可以帮我吗?

0 个答案:

没有答案