【问题标题】:AngularJS UI-GRID: editDropdownOptionsFunction and async $http.getAngularJS UI-GRID:editDropdownOptionsFunction 和异步 $http.get
【发布时间】:2016-10-23 15:35:09
【问题描述】:

我使用 ui-grid v3.2.9。我有带有内联编辑的网格,这是编辑单元格之一 - 下拉控件。每次单击此单元格时,我都想获取用于下拉控件的数组。我尝试使用 editDropdownOptionsFunction 下载 json 以进行下拉:

      columnDefs: [

        {
            name: 'serial',
            displayName: 'Serial',
            width: 100,
            enableCellEdit: true,
            editableCellTemplate: 'ui-grid/dropdownEditor',
            editDropdownIdLabel: 'id',
            editDropdownValueLabel: 'id',
            editDropdownOptionsFunction: function(rowEntity, colDef){
                var res = [];
                $http.get('index.php?r=docs/serialsjson2&recid=' + rowEntity.id)
                    .success(function (data) {
                        res = data;                                     
                    });

                return res;
            }
        },

    ],

但据我了解,$http.get 完成得太晚了,并且没有填充 dropdownarray。 请帮帮我。我需要如何在点击时从服务器向下拉小部件请求数据?

【问题讨论】:

    标签: javascript angularjs dropdown ui-grid


    【解决方案1】:

    在数据返回成功函数后加载下拉数据。唯一意味着更快地获取数据的方法是通过简单的步骤检索数据,而不需要更多的循环或查询操作[re-factor]。

    如果没有发生这种情况,您可以尝试在 http 拦截器中添加 spinner(loader) 并禁用下拉菜单,直到填充数据。

    有很多方法可以为下拉菜单实现微调器和隐藏覆盖。 下面是一个示例链接 Spinner and Overlay

    【讨论】:

      【解决方案2】:

      你需要从 $http 返回承诺:

      return $http.get('index.php?r=docs/serialsjson2&recid=' + rowEntity.id).then(function (data) {
                return data;                                     
      });
      

      也使用 .then 代替 .success----success 已弃用

      【讨论】:

        猜你喜欢
        • 2015-09-28
        • 2016-03-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-30
        • 2016-05-09
        • 1970-01-01
        相关资源
        最近更新 更多