Kendo-UI Grid不通过AngularJS呈现数据

时间:2014-10-07 10:19:26

标签: angularjs kendo-ui kendo-grid

我使用Restangular来解决响应(产品列表)......我知道这个问题已经解决好了。

我是Kendo-UI的新手。但是已经建立了如下的基本测试网格。我正在使用k-rebind,因为在创建网格时可能无法解析products数组。

<kendo-grid k-options="mainGridOptions" k-rebind="products"></kendo-grid>

在我的控制器中:

$scope.products = [];
        $scope.therapyAreas = [];
        $scope.dropDownTAs = [];

        prProductService.getProducts().then(function(products) {
            $scope.products = products;
            prTAService.getTAs().then(function(tas) {
                $scope.therapyAreas = tas;
                for(var i = 0; i < $scope.therapyAreas.length;i++) {
                    $scope.dropDownTAs.push({id: $scope.therapyAreas[i].id, therapyArea: $scope.therapyAreas[i].therapyArea});

                }               
            });
        });

        $scope.mainGridOptions = {
                dataSource: {
                    data: $scope.products                    
                },
                height: 550,
                scrollable: true,
                sortable: true,
                filterable: true,
                pageable: {
                    input: true,
                    numeric: false
                },
                columns: [
                    "productName",
                    "activeIngredients",
                    "productComments",
                    "gpt",
                    "ta"
                ]
        };
    }]) 

我知道正在返回产品数组,我原以为k-rebind会看产品数组进行更改,所以当它解决后会刷新UI ...没有这样的运气。

我尝试将手动数组中的bashing压入数据源以镜像产品数组的响应,并且网格工作正常。

此致

2 个答案:

答案 0 :(得分:4)

你绝对正确的是Kendo UI Grid最初无法访问数据,所以当Grid在页面上呈现时,它只会绑定到一个空数组 - 没有数据。您也可以在此方案中使用k-rebind属性,因为它应该留意范围何时更改。

但是,您遗漏的一件重要事情是k-rebind应设置为 相同的 作为您的选项,如this documentation article中所述。这很容易被遗漏,但我之前在类似的场景中使用过它。

所以,虽然我还没有对此进行测试,但我相信以下内容适合您:

<kendo-grid k-options="mainGridOptions" k-rebind="mainGridOptions"></kendo-grid>

答案 1 :(得分:1)

我得到了同样的错误。但这对我有用:

在html视图代码中:

WV2.height = 0.095 * height
角度控制器中的

<kendo-grid data-source="vm.kendoData.data"
            sortable="true" 
            options="vm.gridOptions">
</kendo-grid>
相关问题