我在Cordova应用程序(Android)中使用Backbone中的脚本,在5s内冻结应用程序,无论如何我不能以不同的方式。
所以我想在脚本运行之前加载一条加载消息,但是视图没有更新。
我可以等待更新视图以使用事件运行脚本吗?
以下是代码:
touchable.get("canvas").$el.parent().hide(); // A canvas to be hidden, but still on screen
this.$el.show(); // The view to replace canvas elem, didn't show up on screen
this.model.draw_full_image(); // Freezing
修改
加载视图:
var SavingView = Backbone.View.extend({
el: '.saving',
show: function() {
touchable.get("canvas").$el.parent().hide();
this.$el.show();
this.model.draw_full_image(); // Long script
},
hide: function() {
// Show the canvas again, after freeze
}
});
画布视图:
var Canvas = Backbone.View.extend({
tagName: "canvas",
initialize: function() {
this.ctx = this.$el[0].getContext("2d");
},
render: function() {
$(".canvas").append(this.$el);
this.el.width = screen_size.w;
this.el.height = screen_size.h - this.$el.offset().top;
},
clear: function() {
this.ctx.clearRect(0, 0, this.el.width, this.el.height);
},
draw_full_image: function(e) {
// Long process here
},
// Saving image (part of process)
save: function(canvas_model) {
window.canvas2ImagePlugin.saveImageDataToLibrary(
function(msg){
saving.hide();
window.plugins.toast.show("La photo a bien été enregistrée !", "long", "bottom");
},
function(err){
saving.hide();
window.plugins.toast.show("Une erreur s'est produite lors de l'enregistrement, veuillez réessayer.", "long", "bottom");
},
canvas_model
);
}
});
答案 0 :(得分:0)
你试过了吗?
this.$el.append('Your message !');