是否可以强制 RequireJS 重新加载文本依赖项?
我想使用 RequireJS 从服务器获取 JSON 格式的数据。我从不同的来源请求数据,然后在回调中显示它。像这样:
require(
['text!/api/services/', 'text!/api/categories/1/'],
function(services_json, category_json) {
var services = $.parseJSON(services_json);
var category = $.parseJSON(category_json);
// displaying services and category.
}
);
我的问题是,我时不时需要重新加载一些对象(如果它们已更改),但 RequireJS 不会第二次请求它,因为它不知道数据已更改。是否可以强制它重新加载一些数据?或者从“缓存”中删除这些数据?
I want to use RequireJS to get data from server in JSON format. I request data from different sources and than display it in the callback. Like this:
require(
['text!/api/services/', 'text!/api/categories/1/'],
function(services_json, category_json) {
var services = $.parseJSON(services_json);
var category = $.parseJSON(category_json);
// displaying services and category.
}
);
My problem is that from time to time I need to reload some objects (if they have been changed), but RequireJS will not request it second time, because it doesn't know that data has been changed. Is it possible to force it to reload some data? or remove this data from "cache"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
提取 JSON 听起来像是 backbonejs 中模型的典型用例。
你可能想调查一下。我不知道有什么方法可以用 requirejs 重新加载。
想想看...为什么不使用 jQuery AJAX 请求来时不时地获取 JSON 呢?
Pulling in JSON sounds like a typical use case for models in backbonejs.
You might want to look into that. I am not aware of any way to reload with requirejs.
Come to think of it... why dont you use jQuery AJAX requests, to get the JSON from time to time?