[英]Require.js model collection fetch difficulty
Okay I'm going to do my best to explain this. 好吧,我将尽力解释这一点。
I am using require.js. 我正在使用require.js。 I have a file named ScheduleView.js and it loads Subject.js .
我有一个名为ScheduleView.js的文件,它会加载Subject.js 。
Subject.js Subject.js
define([
'jquery',
'underscore',
'backbone',
'libs/myFunctions/schedule/collections/SubjectList'
], function($, _, Backbone, SubjectList){
var Subject = Backbone.Model.extend({
initialize: function(){
subjectList = new SubjectList;
subjectList.fetch({
success: function(){
console.log('yay! fetched');
}
})
...
return Subject;
The Subject model is used ALOT. 主题模型大量使用。 And I can't make it fetch the data every time.
而且我不能让它每次都获取数据。 That's just a waste of performance.
那只是浪费性能。 It's also too much of a hassle to initialize Subject once in the ScheduleView and pass on the variable;
在ScheduleView中一次初始化Subject并传递变量也很麻烦。
Are there other alternatives of doing this? 还有其他选择吗?
Hope you understand the problem. 希望您理解问题。 Thanks
谢谢
Aha! 啊哈! Inside 'libs/myFunctions/schedule/collections/SubjectList' i simply wrote:
在“ libs / myFunctions / schedule / collections / SubjectList”里面,我简单地写道:
var subjectList = new Subject
return subjectList
That way I could simple include the link every time I needed it with only having it fetched the information once. 这样,我可以在每次需要链接时简单地包含该链接,而只需一次获取信息即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.