我对角度和骨干等东西很陌生,并且试图更好地理解结构。我构建了一些视图,但如果我在模板块中留下任何空格,它会打破一切。如何为骨干视图制作外部模板
var HomeView = Backbone.View.extend({
template: '<h1>Home</h1><p>This is the first test. I think this is the way.</p>',
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template);
}
});
var AboutView = Backbone.View.extend({
template: '<h1>About</h1><p>This is the second test. I think this is the way.</p>',
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template);
}
});
var CoolView = Backbone.View.extend({
template: '<h1>Cool</h1><p>This is the third test. I think this is the way.</p>',
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template);
}
});
var AppRouter = Backbone.Router.extend({
routes: {
'': 'homeRoute',
'home': 'homeRoute',
'about': 'aboutRoute',
'cool': 'coolRoute',
},
homeRoute: function() {
var homeView = new HomeView();
$("#content").html(homeView.el);
},
aboutRoute: function() {
var aboutView = new AboutView();
$("#content").html(aboutView.el);
},
coolRoute: function() {
var coolView = new CoolView();
$("#content").html(coolView.el);
}
});
var appRouter = new AppRouter();
Backbone.history.start();
是否有一种方法可以使外部模板在JavaScript之外进行拉动。如果页面非常精细,什么是最佳实践?
这是我的jsfiddle链接。
https://jsfiddle.net/galnova/k4ox8yap/14/