从网络套接字接收特定数据后仅更改特定值 [英] Change only the specific value after receving the specific data from web sockets

查看:25
本文介绍了从网络套接字接收特定数据后仅更改特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我展示了一个长 JSON 结构的特定部分

Below I'm showing a specific part of a long JSON structure

var user = {
    map: {
        width: 785,
        height: 791
    },
    image: {
        name: "image.png",
        size: {width:32}
    },
    properties:[{
        firstName: "Bob",
        lastName: "Jones",
    }]
};

现在,如果我要更新上述 JSON 结构中的任何值,比如 firstName 已从Bob"更改为Angel",我如何有效地替换 firstName 以便在我使用 web 时将其反映在 DOM 中插座..由于 JSON 很大,我将使用 ng-repeat 来绑定数据.目前我正在重新加载整个数据以查看我不需要做的 DOM 变化..

Now if I'm updating any value in the above JSON structure say firstName is changed from "Bob" to "Angel" how can I efficiently replace the firstName so that it will be reflected in the DOM as I'm using web sockets.. Since the JSON is huge I will be using ng-repeat to bind the data. Currently I'm reloading the entire data to see the change in the DOM which I don't need to do..

如果有任何与该特定 JSON 相关联的内容,我将通过网络套接字获取更新后的名称和主键

From the web socket I will be getting the updated name and the primary key if there is any associated with that particular JSON

推荐答案

只要您从 AngularJS 处理程序函数中更新您的 JSON 结构(实际上是您的 JavaScript 对象),对数据的任何更改都会立即反映到呈现的视图中处理函数完成后.

As long as you update your JSON structure (actually your JavaScript object) from within an AngularJS handler function, any changes to the data are reflected to the rendered view immediately after handler functions have completed.

这篇关于从网络套接字接收特定数据后仅更改特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆