小编Dev*_*ern的帖子

如何更新角度阵列中的现有项目(外部已更改)?

我是Angular的新手,我正在努力更新我的Angular数组中已经外部更改的现有项目(而不是通过Angular驱动的UI).

这是用例...我的网页是通过服务器端调用填充的,我将数组加载到Angular并显示在列表中.

现在,如果服务器上的数据发生变化并且在表中插入了新记录,则会通知我的页面的JavaScript,并通过"push"成功地将新记录插入到Angular数组中(Ref.以编程方式在Angular JS中插入数组值) .

但是,当更改现有记录时(在服务器端/不通过Angular驱动的UI),我的页面也会得到通知.关于如何在Angular数组中更新正确的记录,我想说空白了?我是否在Angular文档中遗漏了查询/更新方法?

这是我目前的代码看起来像...

    //The HTML UI updates to reflect the new data inserts.
    <div ng-repeat="item in items">        
        <p class="priority">{{item.priority_summary}}</p>
        <p class="type">{{item.type}}</p>
    </div>
Run Code Online (Sandbox Code Playgroud)

这是脚本......

    var app = angular.module('DemoApp', []);

    <!-- Define controller -->
    var contrl = app.controller("MainController", function ($scope) {

    $scope.items = [{
        "status": "New",
            "priority_summary": "High"
    }, {
        "status": "New",
            "priority_summary": "High"
    }, {
        "status": "New",
            "priority_summary": "High"
    }, {
        "status": "New",
            "priority_summary": "High"
    }];

//The insert works fine. The question is how do …
Run Code Online (Sandbox Code Playgroud)

javascript arrays angularjs

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

angularjs ×1

arrays ×1

javascript ×1