Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用socket.io更新角度范围,但我的视图未更新_Javascript_Arrays_Angularjs - Fatal编程技术网

Javascript 使用socket.io更新角度范围,但我的视图未更新

Javascript 使用socket.io更新角度范围,但我的视图未更新,javascript,arrays,angularjs,Javascript,Arrays,Angularjs,在angular中构建推送通知时,我遇到了一个问题:我的$scope模型正在按预期更新,但在ng repeat中我的视图没有改变 这就是我的工厂的样子 var m = JSON.parse(message); var n = JSON.parse(m.data.message); var type = n.type; $rootScope.$apply(function() { $rootScope.notifications[n.type].items.push(n);

在angular中构建推送通知时,我遇到了一个问题:我的$scope模型正在按预期更新,但在ng repeat中我的视图没有改变

这就是我的工厂的样子

var m = JSON.parse(message);
var n = JSON.parse(m.data.message);
var type = n.type;

$rootScope.$apply(function() {
      $rootScope.notifications[n.type].items.push(n);
      $rootScope.notifications[n.type].unread++;
});
我的ng重复代码在jade模板中看起来像这样

ul.nav.navbar-nav
li.dropdown.dropdown-list(ng-repeat="(key,notification) in notifications" uib-dropdown="" ng-if="key != 'All'")
    a(uib-dropdown-toggle="" md-ink-ripple="")
        em.fa(ng-class="'fa-'+notification.icon")
        .label.label-danger(ng-if="notification.unread > 0") {{notification.unread}}
    ul.dropdown-menu(class="animated flipInX")
        li
            // START list group
            .list-group
                // list item
                a.list-group-item(ng-repeat="item in notification.items | limitTo:10" ng-if="item.read == 0")
                    .media-box
                        .pull-left
                            em.fa.fa-2x.text-info(ng-class='"fa-"+item.icon')
                        .media-box-body.clearfix
                            p.m0 {{item.title}}
                            p.m0.text-muted: small {{item.content}}
                a.list-group-item(href='' ng-if="notification.items.length == 0")
                    .media-box
                        .pull-left
                            em.fa(ng-class="'fa-'+notification.icon")
                        .media-box-body.clearfix
                            small No unread notifications.
                a.list-group-item(href='' ng-if="notification.items.length > 10")
                    small More notifications
                    .label.label-success.pull-right {{notification.items.length - 10}}

你确定
n.type
就是你想象的那样,看起来你在两次解析同一个JSON?我打印了n.type,这正是我所期望的。我尝试用我期望的替换n.type,例如:
$rootScope.notifications.HelpDesk.items.push(n)
仍然不起作用。你确定
n.type
就是你想象的那样,看起来你在两次解析同一个JSON?我打印了n.type,这正是我所期望的。我尝试用我期望的替换n.type,例如:
$rootScope.notifications.HelpDesk.items.push(n)但它仍然不起作用。