骨干浏览+递延车把模板载入

编程入门 行业动态 更新时间:2024-10-07 08:25:11
本文介绍了骨干浏览+递延车把模板载入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图加载车把模板,并通过延期对象/承诺使他们,但是当我通过把在deferreds重构了code,错误发生:

I am trying to load handlebars templates and rendering them via deferred objects / promises, but when i refactored the code by putting in deferreds , errors are occurring:

我的看法如下:

var indexView = Backbone.View.extend({ initialize: function (options) { this.options = options || {}; manager.getTemplate('path/to/template').then(function(tpl){ // tpl is a handlebar compiled template,returned by getTemplate this.template = tpl; this.render(); // that causes // Uncaught TypeError: Object #<Object> has no method 'render' // "this" is Backbone.View.extend.initialize }); }, render: function (){ // this.options is undefined this.$el.html(this.template(this.options.data)); return this; } });

我不明白如何我应该为什么在渲染()函数this.options从。于是()函数达到this.render,也就是现在不确定谢谢

i can't understand how i'm supposed to reach this.render from the .then() function and also why in the render() function this.options is now undefined Thank you

推荐答案

谨防恶性这个!它可能不是你认为它是当你的延迟函数被调用,特别是在jQuery的参与。

Beware the malignant this! It may not be what you think it is when your deferred function is called, especially where jQuery is involved.

尝试

initialize: function (options) { this.options = options || {}; var myself = this; manager.getTemplate('path/to/template').then(function(tpl){ // tpl is a handlebar compiled template,returned by getTemplate myself.template = tpl; myself.render(); }); }

更多推荐

骨干浏览+递延车把模板载入

本文发布于:2023-06-02 01:01:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/430991.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:车把   骨干   递延   模板

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!