模型更改时无法进行部分刷新

时间:2015-08-31 20:37:21

标签: javascript angularjs

我有一个下拉列表,其中包含以下代码:

<span class="bluedept">Department:</span>
            <select class="selectpicker deptpicker" selectpicker ng-model="department" ng-controller="CaseListCtrl" ng-change="getCalendar();">
                <option ng-repeat="department in departments track by $index">{{department.CourtRoom}}</option>
            </select>

然后我在我的控制器中有这个:

JBenchApp.controller('CaseListCtrl', ['$scope', '$http', 
  function ($scope, $http) {
      // Case list stuff here

      $scope.getCalendar = function () {
          var e = document.getElementById("deptSelect");
          var department = e.options[e.selectedIndex].text;
          console.log(department);

          $http.get('http://10.34.34.46/BenchViewServices/api/Calendar/LA/' + department + '/08-27-2015').success(function (response) {
              $scope.cases = response;
          });
      }

          $http.get('http://10.34.34.46/BenchViewServices/api/CourtDept/LA').success(function (response) {
              $scope.departments = response;
          });


  }]);

$ scope.cases使用新数据进行更新,但部分不会更改以匹配该数据。如何刷新局部视图?

编辑添加部分视图代码:

<div class="row" ng-show="$parent.loggedin">
    <div class="col-sm-12 calselectrow">
        <div class="inner-addon left-addon">
            <span class="glyphicon glyphicon-calendar calicon"></span>

            <input type="text" id="calpick" ng-model="date" jdatepicker />
            <i class="glyphicon glyphicon-calendar calclick"></i>

            <a href="#" class="btn btn-primary flat-edge">>></a>

            <span class="bluedept">Department:</span>
            <select class="selectpicker deptpicker" id="deptSelect" selectpicker ng-model="department" ng-controller="CaseListCtrl" ng-change="getCalendar();">
                <option ng-repeat="department in departments track by $index">{{department.CourtRoom}}</option>
            </select>
        </div>
    </div>
</div>
<div class="row" ng-show="$parent.loggedin">
    <div ng-controller="CaseListCtrl">
        <div class="col-sm-8 col-sm-offset-2 caselist" ng-repeat-start="case in cases track by $index">
            <div class="sequence">
                <input type=text class="seq-box" size="1" value="{{case.sequence}}" />
            </div>
            <div class="casetitle">
                <span class="caselink">{{case.Case_Number}}</span>
                <a href="calendar" data-toggle="tooltip" data-placement="top" title="Calendar" class="btn btn-xs btn-danger calicon-view" tooltip>
                    <span class="glyphicon glyphicon-calendar"></span>
                </a>
                <a href="documents/{{case.Case_Number}}" data-toggle="tooltip" data-placement="top" title="Documents" class="btn btn-xs btn-danger calicon-view" tooltip>
                    <span class="glyphicon glyphicon-file"></span>
                </a>
                <a href="parties/{{case.Case_Number}}" data-toggle="tooltip" data-placement="top" title="Parties" class="btn btn-xs btn-danger calicon-view" tooltip>
                    <span class="glyphicon glyphicon-user"></span>
                </a>
                {{case.Case_Title}}
            </div>
        </div>
        <div class="col-sm-8 col-sm-offset-2 caselist-bottom">
            <div class="col-sm-9 col-sm-offset-1">
                <div class="hearing-time">{{case.Sched_Time}}&nbsp;{{case.AmPm}}</div>
                <div class="hearing-title">{{case.Event}}</div>
            </div> 
        </div>
        <div ng-repeat-end></div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

尝试通过他们的ID跟踪案例或从ng-repeat中删除跟踪。

ng-repeat not update model with track by

更新:

我认为问题是您在html中使用两次ng-controller导致第二个范围被创建。将html包装在容器div中,并仅将ng-controller属性应用于此。