gpt4 book ai didi

javascript - Backbone.js:解码获取的数据

转载 作者:行者123 更新时间:2023-11-30 18:27:06 25 4
gpt4 key购买 nike

使用 Backbone.js 我需要执行以下任务:

1) 从服务器获取数据
2) 解码获取的数据(对该数据执行一些操作)
3) 将这些数据注入(inject)到我的 View 中,然后注入(inject)到我的 HTML 模板中

关于第二个任务(解码获取的数据),
在 MVC 上下文中制作它的最佳位置/方式/模式是什么?


一些要编码的数据是关于权利的,看起来像这样:

READ               = 0x01,
CREATE_USER = 0x08,
CREATE_WORKSPACE = 0x10,
UPDATE = 0x20,

我需要用掩码对它们进行位运算进行编码。

最佳答案

您可以提供自己的 parse模型中的实现:

parse model.parse(response)

parse is called whenever a model's data is returned by the server, in fetch, and save. The function is passed the raw response object, and should return the attributes hash to be set on the model.

所以你会有这样的东西:

parse: function(response) {
var parsed_response = _(response).clone();
// do your bit wrangling on parsed_response and remove what you don't want...
return parsed_response;
}

关于javascript - Backbone.js:解码获取的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10566244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com