首頁  >  問答  >  主體

javascript - angularjs想要操作ajax取得到的資料總是報錯

.controller('alistcontrol',function($scope, aliService){
    $scope.advlist = {
                            id        :    "",
                            status    :    "",
                            content    :    "",
                            qTime    :    "",
                            answer    :    "",
                            aTime    :    "",
                        }
    aliService.getlis().then(function(data){
        var tempdata = angular.fromJson(data);
        $scope.advlist = tempdata.result;
        $scope.$watch('advlist',function(newValue){
            if(!newValue){
                $(".al_nonedis").show();
            }
        });
        console.log(tempdata.result);
        for(var i = 0;i<=tempdata.result.length;i++){
            console.log(tempdata.result[i].status);
            if(tempdata.result[i].status == "未回复"){
                var temp = document.getElementById(tempdata.result[i].id);
                $(temp).children("#al_title").addClass("blackword");
                $(temp).children("#al_awswer").hide();
            }
        }
    })
})

程式碼如上,這裡我想比較取得到的資料中的某幾項,但是瀏覽器測試一直報錯

#求各位大神看看如何解決,剛接觸angular沒多久。 。 。 。 。 。 。 。 。 。 。 。

为情所困为情所困2662 天前796

全部回覆(3)我來回復

  • PHP中文网

    PHP中文网2017-07-05 10:51:14

    找到問題了,同事幫忙看了一下,是for裡面寫錯了,應該是<寫成了<=…………習慣性從1開始循環這裡從0開始就弄錯了_(:з”∠) _

    回覆
    0
  • 阿神

    阿神2017-07-05 10:51:14

    console.log(tempdata.result); 輸出什麼啊?

    回覆
    0
  • 代言

    代言2017-07-05 10:51:14

    這裡說了報錯,去看看manageController 第133行

    回覆
    0
  • 取消回覆