简体   繁体   English

如何动态更改 kendo TreeList 的列集合集?

[英]How to change the columns collection set of a kendo TreeList dynamically?

Try to change the columns list dynamically via a query...尝试通过查询动态更改列列表...

When I construct the TreeList, I call for columns:当我构造 TreeList 时,我要求列:

$("#treelist").kendoTreeList({
        columns: AnalyseCenterSKUService.getKPIColumnList($scope)

If I return a simple array with the fields, it's working..如果我返回一个带有字段的简单数组,它就可以工作..

If I call a $http.get (inside my getKPIColumnList(..) function) which add some columns to the existing array of columns, the TreeList is not constructed correctly.如果我调用$http.get (在我的 getKPIColumnList(..) 函数中)将一些列添加到现有的列数组中,则 TreeList 构造不正确。

Any suggestion will be really appreciated: :)任何建议将不胜感激::)

EDIT 22-10-2019 09:00编辑22-10-2019 09:00

Treelist init树列表初始化

$("#treelist").kendoTreeList({
        columns: AnalyseCenterSKUService.getKPIColumnList($scope), 
        scrollable: true,
        columnMenu : {
            columns : true
        },
        height: "100%", 
        dataBound: function (e) {
            ExpandAll();
        },
        dataSource: {
            schema: {
                model: {
                    id: "id",
                    parentId: "parentId",
                    fields: {
                        id: { type: "number" },
                        parentId: { type: "number", nullable: true },
                        fields: {
                            id: { type: "number" },
                            parentId: { type: "number", nullable: false }
                        }
                    }
                }
            },
            transport: {
                read: {

                    url: "/api/AnalyseCenter/GetWorkOrderTree/0",
                    dataType: "json"
                }
            }
        }

The getKPIColumnList return an static array + some push with dynamic columns (from DB) getKPIColumnList 返回一个 static 数组 + 一些带有动态列的推送(来自 DB)

angular.module('AnalyseCenterDirectives')
.service ('AnalyseCenterSKUService', function ($http) {

        var toReturn = [ {field: "Name", title: "Hiérachie SKU", width: "30%" }, ..., ..., .... ];

I try in this function to push DB result我尝试在这个 function 中推送数据库结果

    return $http.get("/api/AnalyseCenter/GetWorkOrderHistorianAdditonalColumns?equipmentName=" + equipmentName)
             .then(function (result) {
                 var data = result.data;
                 if (data && data !== 'undefined') {
                     var fromDB = data;


                     angular.forEach(fromDB, function (tag) {
                         var tagName = tag.replace(".","_");
                         toReturn.push({                                 
                              field: tagName, title: tag, width: '10%',
                              attributes: { style: "text-align:right;"}                                                         })
                        })

The stored procedure GetWorkOrderHistorianAdditonalColumns returns a list of string (future column)存储过程GetWorkOrderHistorianAdditonalColumns返回一个字符串列表(未来列)

That is because ajax is async , that means your tree list is being initialized before the request finishes.那是因为 ajax是 async ,这意味着您的树列表正在请求完成之前被初始化。 A classic question for JavaScript newcomers. JavaScript 新手的经典问题。 I suggest you take a while to read about ajax, like How does AJAX works for instance.我建议您花点时间阅读 ajax,例如AJAX 如何工作

Back to your problem.回到你的问题。 You need to create your tree list inside the success callback(I can't give you a more complete solution since I don't know what you're doing inside your function or which framework you're using to open that ajax request) with the result data, which is probably your columns.您需要在成功回调中创建树列表(我无法为您提供更完整的解决方案,因为我不知道您在 function 中正在做什么,或者您使用哪个框架来打开该 ajax 请求)结果数据,这可能是您的列。 Then it would work as if you're initializing it with arrays.然后它会像你用 arrays 初始化它一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM