Ste*_*ven 5 javascript json backbone.js zepto parse-platform
我要么非常累,要么真的很困惑...但我不确定...我有一个parse.com javascript设置(它完全像backbone.js只是用解析而不是骨干).我有一个模型和一个集合,一切都有效.但是darn toJSON(); 不起作用,它只是在console.log中返回一个[]但是如果我在Chromes控制台中运行相同的函数它会工作并返回正确的值.
任何帮助!?
所有这些可爱的代码都包含在一个文件准备好了(并且它有一些其他代码不是相关的,是的,我有Parse.initialize()它.
var Schedule = Parse.Object.extend({
className: "schedule"
});
var ScheduleList = Parse.Collection.extend({
model: Schedule
});
schedule = new ScheduleList();
schedulejs3 = schedule.toJSON();
schedule.query = new Parse.Query(Schedule);
schedule.query.ascending("date");
schedule.query.limit('500');
schedulejs2 = schedule.toJSON();
schedule.fetch();
schedulejs = schedule.toJSON();
console.log(schedulejs,schedulejs2,schedulejs3); <-- All three return []
var ScheduleView = Parse.View.extend({
el: $("#schedule-holder"),
initialize: function() {
this.schedule = new ScheduleList();
this.schedule.query = new Parse.Query(Schedule);
this.schedule.query.ascending("date");
this.schedule.query.limit('500');
this.schedule.fetch();
this.schedule.js = this.schedule.toJSON();
this.render;
},
render: function() {
var template = Handlebars.compile($("#schedule-item").html());
$(this.el).html(template({shows: this.schedule.toJSON()}));
return this;
}
});
var App = new ScheduleView().render();
Run Code Online (Sandbox Code Playgroud)
但是如果我在Chrome中打开控制台并运行schedule.toJSON(); 我得到了正确的价值......正如你所看到的那样,我已经扼杀了我的骨干.设置试图解决这个问题(因为你想知道为什么一切都到处都是).还有一点,我正在使用Zepto.js而不是jQuery.
谢谢!
fgu*_*len 19
可能在你执行schedule.toJSON()它时仍然是空的.
请记住,这Collection.fetch()是一种异步方法.
尝试修改此行:
schedule.fetch();
Run Code Online (Sandbox Code Playgroud)
这样:
schedule.fetch({ success: function() { console.log( "what about now?", schedule.toJSON() ) } };
Run Code Online (Sandbox Code Playgroud)
(可能你会遇到一个上下文问题,尝试使schedule变量可以访问 success处理程序)
| 归档时间: |
|
| 查看次数: |
3444 次 |
| 最近记录: |