mik*_*ana 1 javascript javascript-framework singlepage backbone.js
我正在努力将单页应用程序转换为backbone.JS.下面的视图使用body标签作为tagName - 即,我希望视图占用页面的整个内容.我不想使用容器div或其他黑客.
var ThingView = Backbone.View.extend({
tagName : "body",
...
// Show the HTML for the view
render : function() {
console.log('Displaying thing')
$(this.el).append('<h1>test</h1>');
console.log('finished')
console.log($(this.el))
return this; // For chaining
Run Code Online (Sandbox Code Playgroud)
渲染时,我明白了
finished
[
<body>?
<h1>?test?</h1>?
</body>?
]
Run Code Online (Sandbox Code Playgroud)
但是在我检查DOM之后,身体不再有文本了.
tagName表示如果构造函数没有提供el,Backbone应该使用哪个标记来创建它.创建的元素不会自动插入DOM.
最简单的方法可能是创建您的视图,其el设置为body:
new ThingView({el:'body'})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2136 次 |
| 最近记录: |