回调后出现“无法设置未定义的属性'isNew'”错误。如何解决这个问题?

时间:2019-03-27 12:15:16

标签: angularjs

回叫后,有一些赋值语句和方法要调用。 代码如下。 调用以下代码后 $ scope.dataService(_url,“ GET”)。then(函数(数据) 它提示错误:无法读取未定义的属性“ division” 但是我收到的响应很有价值,并且也尝试在控制台中打印。 有办法解决吗? 我收到的回复是一个对象。

$scope.getData = function (designNumber, division) {
        if (designNumber === '')
            return;
        $scope.getSetting();
        $scope.Saved_failed = "";
        $scope.count = 0;
        $scope.code = null;
        $scope.response = null;
        document.getElementById("autoGenerate").className = 
  "hostInputText";
        var encodedesignnum = encodeURIComponent(designNumber);
        encodedesignnum = encodedesignnum.replace(/'/g, "''");
        _url = $scope.getUri() + "Design/?division=m&DesignNumber=" + 
  encodedesignnum;
        $scope.footerMessage = "Loading " + designNumber;
        $scope.dataService(_url, "GET").then(function (data) {
            $scope.footerMessage = "";
            var design = [];
            design = _.filter(data, function (d_data) { return d_data.division == division; });
            $scope.data = design[0];
            $scope.currentData = $scope.data;
            $scope.seasonCopy = angular.copy($scope.currentData)

           console.log($scope.currentData.division);
            if($scope.currentData.division!=undefined || 
  $scope.currentData.division!="")
                $scope.loadMerchGroup($scope.currentData.division);
            $scope.loadMerchGroups();
            // $scope.getDivisionval($scope.currentData.division);
            // $scope.thisDesign($scope.currentData.designType, 'code');
            // $scope.thisProductType($scope.currentData.productType, 
               'code');
            // $scope.thisSeason($scope.currentData.season, 'code');
            // $scope.thisStage($scope.currentData.dzgn_stage, 'code');
            $scope.currentData.isNew = false;
            $scope.currentData.isDirty = false;
            $scope.dirty = false;
            $timeout(function () {
                if ($scope.currentData.cont_code != undefined && 
$scope.currentData.cont_code != "")
                    $scope.thisContent($scope.currentData.cont_code, 
'code')
                $scope.dirty = false;
                $scope.dup_data = angular.copy($scope.currentData);
                for (var i = 0; i < $scope.merchGroupDescription.length; 
i++) {
                    if ($scope.merchGroupDescription[i].mg_require == 
"Y") {
                        $scope.count += 1;
                        document.getElementById("mech" + i).placeholder = 
"--Required--";
                        document.getElementById("mechgrp" + 
i).placeholder = "--Required--";
                    }
                    else {
                        document.getElementById("mech" + i).placeholder = 
"";
                        document.getElementById("mechgrp" + 
i).placeholder = "";
                    }
                }

            }, 1500);


        }, function (res) {
            $scope.handleError(res);
        });

    };

0 个答案:

没有答案