angular页面数据加载时,存在遗漏,刷新页面后,遗漏的数据被显示出来

页面初次加载后,不是一直存在这个遗漏问题,时有,时没有。遗漏的数据,在刷新页面后出现!图片描述

图片描述

所有的数据与样式加载都是通过angular实现的,
代码如下:
//初始$scope.tablebody

$scope.vstablehead = [];
$scope.settablebody = function () {
    for (var i = 0; i < $scope.specification.length; i++) {

        //$scope.tablehead.push($scope.specification[i].name)
        $scope.tablebody.push({'options': []});  //创建子项
        $scope.recursionTablebody.push([]);//创建递归源子项[]


        for (var j = 0; j < $scope.specification[i].entries.length; j++) {
            if ($scope.specification[i].entries[j].isSelected) {
                //$scope.initisChecked($scope.specification[i].name)
                $scope.tablebody[i].options.push($scope.specification[i].entries[j].value)
                //if ($scope.tablehead.length==0) {
                //    $scope.tablehead.push($scope.specification[i].name)
                //} else {
                //    for (let y = 0; y < $scope.tablehead.length; y++) {
                //        if ($scope.specification[i].name != $scope.tablehead[y]) {
                //            $scope.tablehead.push($scope.specification[i].name)
                //        }
                //    }
                //}


            }

        }

        for (var p = 0; p < $scope.tablehead.length; p++) {


        }
        if ($scope.tablebody[i].options.length != 0) {
            $scope.tablehead.push($scope.specification[i].name)

            $scope.vstablehead.push($scope.specification[i].name)
        }

        console.log($scope.tablehead)

    }
    // $scope.tablebody.push({'options': []})  //创建子项
    // $scope.recursionTablebody.push([])//创建递归源子项[]
    for (var d = 0; d < $scope.tablebody.length; d++) {

        //console.log($scope.tablebody[d].options)
        $scope.recursionTablebody[d] = $scope.tablebody[d].options

    }
    //console.log(JSON.stringify($scope.recursionTablebody))
    // console.log(JSON.stringify($scope.tablebody))
    //初始取得页头
    $scope.tablehead = $scope.gettablehead
    madenew($scope.recursionTablebody)//生成新$scope.tablebody
    console.log(JSON.stringify($scope.tablebody))
}

//初始表格内容

$scope.initisChecked = function (name, index, childItem) {
    var headIndex //页头位置
    $scope.tablehead.push(name)

    $scope.tablebody.push({'options': []})  //创建子项
    $scope.recursionTablebody.push([])//创建递归源子项[]

    if ($scope.tablehead.indexOf(name) == -1) {

            $scope.tablehead.push(name)




        $scope.tablebody.push({'options': []})  //创建子项
        $scope.recursionTablebody.push([])//创建递归源子项[]
    }
    console.log($scope.tablehead)
    ////保存子项  ----begin
    headIndex = $scope.tablehead.indexOf(name)
    if ($scope.tablebody[headIndex].options.indexOf(childItem) == -1) {//不包括才新增
        $scope.tablebody[headIndex].options.push(childItem)
    }
    ////保存子项  ----end


    //console.log(JSON.stringify($scope.tablebody))
    for (var d = 0; d < $scope.tablebody.length; d++) {

        //console.log($scope.tablebody[d].options)
        $scope.recursionTablebody[d] = $scope.tablebody[d].options

    }
    //console.log(JSON.stringify($scope.recursionTablebody))
    // console.log(JSON.stringify($scope.tablebody))
    madenew($scope.recursionTablebody)//生成新$scope.tablebody


}
阅读 2.7k
3 个回答

$scope.$apply();你在控制器的底部加上这一行试试

各位同仁,帮帮忙,这个问题,已经困扰我一周了,谢谢,非常感谢!

有线上demo么?
你在表格数据赋值渲染出来前console一下表头数据,看看是不是全的

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题