使用angularJs中的$ location.path重定向后获取null数组

时间:2015-07-16 10:26:56

标签: javascript jquery angularjs

这是我的控制器代码,我正在调用getResult方法: -

$scope.selectedAnswer = [];
$scope.correctAnswer = [];

$scope.result = function () {
    $(".optionlist").find("li").each(function () {
        if ($(this).attr('id') == 'true') {
            var label = $(this).parent('ul').attr('que-label');
            var value = $(this).find('input[type=checkbox]').attr('value');

            $scope.correctAnswer.push({ "label": label }, { "Option": value   });
            console.log(label);

        }
    });

$scope.getResult = function () {

$location.path("/reviewans");
}

这是我的选项页面块: -

<div class="list-group list_top" data-toggle="items">

<ul class="left1 optionlist" data-value="{{$index+1}}" que-label="{{Questions.QuestionLabel}}">

<li class="list group-items alert alert-danger alert_template" style="display:none">
<a class="close" data-dismiss="alert" aria-label="close">&times;</a><span class="spantext"></span>
</li>

<li ng-repeat="Options in answerlist" ng-if="Questions.QuestionID == Options.QuestionID" id="{{Options.IsCorrectOption}}" ng-show="Options.QuestionID == Questions.QuestionID" ng-click="!IsAutoslide||AutoSlide(Options.QuestionID)">

<a href="#" class="list-group-item"><input type="checkbox" value="{{Options.QuestionOptionID}}" style="display:none">{{Options.OptionText}}</a>
</li>


</ul>

</div>
<div><a class="btn btn-default finish" style="display:none" ng-click="getResult()">Finish</a></div>

这是我的评论页面块: -

<div class="tab-pane fade" id="messages" ng-init="result()">
                        <div class="all_ques_back col-md-12" ng-repeat="ans in correctAnswer">
                            <div class="col-xs-1 col-md-1"><i class="fa fa-times-circle fa-2x col_padd wrong_ans_font"></i></div>
                            <div class="col-xs-9 col-md-10 col_padd"><div class="all_ques" ng-repeat="(key, val) in ans">hello your ans {{val}}</div></div>
                            <div class="col-xs-1 col-md-1 col_padd"><i class="fa fa-angle-right right_arrow"></i></div>
                        </div><!-----end------>

                    </div>

问题是我在使用location.path

重定向后得到了nullAnswer的null结果

1 个答案:

答案 0 :(得分:0)

我看不到你在任何地方填充&#;; scope.correctAnswer&#39; ?也许您想使用&#39; $ scope.selectedAnswer&#39;