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

0 0 spring windows angular.js javascript html5
♣ 五 毛
♣ 五 毛

声望值:298 0人

2018-12-21 11:07:59 提问

关注 0关注

收藏 0收藏, 29浏览

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

图片描述

所有的数据与样式加载都是通过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


}
请先 登录 后评论

3个回答

  • wolfing_85声望 2018-10-15 15:55

    各位同仁,帮帮忙,这个问题,已经困扰我一周了,谢谢,非常感谢!
    请先 登录 后评论
  • 爬墙丶等红杏79声望 2018-10-15 15:55

    有线上demo么?你在表格数据赋值渲染出来前console一下表头数据,看看是不是全的
    请先 登录 后评论
  • l梁上君子141声望 2018-10-15 16:01

    $scope.$apply();你在控制器的底部加上这一行试试
    请先 登录 后评论

注册新账号

悬赏追问
10
  • 10
  • 20
  • 50
  • 100
  • 200
  • 输入数值
发布追问