[英]Rendering of the html page not working
我正在使用Backbonejs框架。 在此框架下,我创建了一个使用Backbonejs,requirejs,下划线和text.js的app.js,我想将html页面加载到div上。 控制台显示html页面已加载,但我无法在屏幕上看到该特定页面。
下面是app.js
define(function (require) {
// "use strict";
var $ = require('jquery'),
underscore = require('assets/js/underscore'),
Backbone = require('assets/js/backbone'),
tpl = require('text!Views/home.html'),
template = _.template(tpl);
return Backbone.View.extend({
render: function () {
el: '#banner',
this.$el.html(template());
return this;
}
});
});
我想将home.html加载到主屏幕(index.html)。 我在index.html中将其称为app.js。 控制台显示以下XHR完成加载:GET“ file:/// D:/Project1/Views/home.html”但是我的index.html页面未显示此home.html
代码有很多问题。
检查此小提琴: http : //jsfiddle.net/rahulsv/c4dveax9/
var tpl = "<div>hello world</div>";
var template = _.template(tpl);
(function(){
var View = Backbone.View.extend({
el: '#banner',
initialize: function(){
this.render();
},
render: function () {
this.$el.html(template());
}
});
var v = new View();
})();
希望能帮助到你。
更新:
要使用requireJs从文件访问模板(因为您正在使用它),可以按照以下步骤进行操作:
模板文件:
<!-- pod.html -->
<h2><%= title %></h2>
<p><%= body %></p>
从JS访问模板:
// view.js
define(["text!templates/pod.html"], function(pod) {
var View = Backbone.View.extend({
template: _.template(pod)
});
});
检查此链接以供参考: http : //kilon.org/blog/2012/11/3-tips-for-writing-better-backbone-views/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.