端材料MD列表不刷新后不刷新

问题描述 投票:0回答:1

您可以看到,列表将通过称为文件的容器迭代。从一开始,它是在我的索引控制器中定义的:

this.files = directoryService.getContent();

所谓的服务“ DirectoryService”提供了目录的内容,并以此为实现:

  app.factory('directoryService', function() {
    var content = [];

    return {
        path,
        getContent: function() {
            console.log("returning directory content");
            return content;
        },

        updateList: function(incfiles) {
            console.log("refreshing directory content");
            content.length = 0;
            Array.prototype.push.apply(content, incfiles);
        }
    };
});

连接到WebDAV服务器后,列表显示了根目录中的所有文件,该文件正常工作。单击列表中的目录后,方法(getContent)再次呼叫服务器(HTTP调用)单击目录的内容:

   $scope.getContent = (file, ev) => {
        console.log(file);
        if (file.type == "directory") {
            listDirectoryContent(currentPath + file.name);
        }
    };

方法listDirectoryContent()将调用服务器并更新与MD-List连接的DirectoryService.files对象:

 listDirectoryContent = (path) => {
        var lclfiles = [];

        var imagePathFolder = 'public/img/folder.svg';
        var imagePathFile = 'public/img/file.svg';
        var imagePathUp = 'public/img/back.svg';

        clientService.client
            .getDirectoryContents(path)
            .then(function(contents) {
                //Set default folders.
                lclfiles.push({
                    ...
                });
                contents.forEach(function(element) {
                    if (element.type == "file") {
                        lclfiles.push({
                            ...
                        });
                    } else {
                        lclfiles.push({
                            ...
                        });
                    }
                }, this);
                directoryService.updateList(lclfiles);
            })
            .catch(function(err) {
                alert(err);
                console.error(err);
            });
    }

});

因此,基本上发生的是,我要等到使用.then()完成HTTP调用。之后,我通过调用DirectoryService.updatelist(NewFiles)将新内容放入DirectoryService.files阵列中。

因此,接下来会发生什么,MD列表在我单击随机文件之前不会更新其内容...单击文件后,列表正确地显示了.files的内容。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

thanks guys
    

我很幸运,遇到了一个也有这个问题的人。我不知道这是否是一个好方法!但这对我有用。 在我的目录服务中,我将更新方法内容包围了以下语句:

updateList: function(incfiles) { console.log("refreshing directory content"); $q.when(true).then(() => { content.length = 0; Array.prototype.push.apply(content, incfiles); console.log(content); }); }

清单现在正在工作。单击目录后,一旦完成HTTP调用,新内容就会显示。

javascript angularjs html angular-material
1个回答
0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.