每行显示的ui.grid数据相同

时间:2016-01-18 13:50:21

标签: angularjs json angular-ui-grid

我正在为数据网格中的每一行使用一个单元格模板。如果我用索引限定json对象,那么值会正确显示,但当然每行都是相同的。如果我删除索引,则所有行都显示相同的值,但值为数组。

--- js文件 (function(){     angular.module(' xxxSurvey')。controller(' EditxxxSurveyController',EditxxxSurveyController);     EditxxxSurveyController。$ inject = [' $ scope',' UserFacilityListService',' xxxSurveyService'];     function EditxxxSurveyController($ scope,UserFacilityListService,xxxSurveyService){         $ scope.dataLoaded = false;         $ scope.currentPage = 1;         $ scope.pageSize = 10;

    // test ui-grid setup

    $scope.dataLoaded = true;

    $scope.editWorksheetOptions = {
        enableSorting: true,
        columnDefs: [
            {
                name: 'all', field: 'MasterPatientId', width: 40,
                enableSorting: false, enableColumnMenu: false, pinnedLeft: true,
                //cellTemplate: '<input type="checkbox" id="i{{COL_FIELD}}">'
                cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.worksheetInfo.MasterProviderId}}</div>'
            },


            {name: 'residentName', field: 'residentName', minWidth: 90, pinnedLeft: true,
                cellTemplate: '<div class="ui-grid-cell-contents">{{grid.appScope.editWorksheetOptions.data[0].ResidentNameLast}}</div>'
            },
            {name: 'residentRoom', field: 'residentRoom', width: 90, pinnedLeft: true},
            {name: 'status', field: 'status', width: 90},
        ],
        data: []
    };

    $scope.$on('FacilitySelected', function() {
        if (UserFacilityListService.getSelectedFacility()) {
            $scope.selectedFacility = UserFacilityListService.getSelectedFacility();
        }
        var promise = xxxSurveyService.getCurrentWorksheet($scope.selectedFacility.MasterProviderId);
        promise.then(
            function(payload) {
                if (payload !== null) {
                    $scope.worksheetInfo = payload.worksheetInfo;
                    $scope.editWorksheetOptions.data = payload.residentData;


                }
            }
        );
    });

}

})();

- json数据

[{&#34; AssessmentId&#34;:1,&#34; WorksheetId&#34:4,&#34; MasterPatientId&#34;:1,&#34; ResidentNameFirst&#34;:&#34 ; XX&#34;&#34; ResidentNameMiddle&#34;:&#34; ^&#34;&#34; ResidentNameLast&#34;:&#34; ZZZ&#34;&#34; ResidentNameSuffix&#34 ;:&#34; ^&#34;}, {&#34; AssessmentId&#34;:2&#34; WorksheetId&#34;:2&#34; MasterPatientId&#34;:2&#34; ResidentNameFirst&#34;:空,&#34; ResidentNameMiddle& #34;:空,&#34; ResidentNameLast&#34;:空,&#34; ResidentNameSuffix&#34;:空}]

- html div id =&#34; editWorksheetGrid&#34; UI栅=&#34; editWorksheetOptions&#34;类=&#34;网格&#34; UI并网钉扎&GT;

1 个答案:

答案 0 :(得分:0)

我有同样的问题。对我来说这是rowIdentity问题。 在控制器中定义以下内容。

$scope.gridOptions.rowIdentity = function (row) {
    return row.ID;  //make sure ID is unique.
};

这解决了我的问题。 感谢