【发布时间】:2015-08-21 16:38:01
【问题描述】:
<script>
var HomeView = Backbone.View.extend({
template: '<h1>Home</h1>',
initialize: function () {
this.render();
},
render: function () {
this.$el.html(this.template);
}
});
var AboutView = Backbone.View.extend({
template: '<h1>About</h1>',
initialize: function () {
this.render();
},
render: function () {
this.$el.html(this.template);
}
});
var AppRouter = Backbone.Router.extend({
routes: {
'': 'homeRoute',
'home': 'homeRoute',
'about': 'aboutRoute',
},
homeRoute: function () {
var homeView = new HomeView();
$(".content").html(homeView.el);
},
aboutRoute: function () {
var aboutView = new AboutView();
$(".content").html(aboutView.el);
}
});
var appRouter = new AppRouter();
Backbone.history.start();
</script>
<ul>
<li><?php echo $this->Html->link('Home',array('controller' =>'pages','action' => 'home')); ?></li>
<li><?php echo $this->Html->link('About',array('controller' =>'pages','action' => 'about')); ?></li>
</ul>
How to convert the code above to make backbone.js like this in manual coding I seen in the NET.
<div id="navigation">
<a href="#/home">Home</a>
<a href="#/about">About</a>
</div>
<div class="content">
</div>
我只是这个人的新手,请帮助我。我现在正在阅读 Backbone js,任何人都可以帮助我解决这个问题。如果你有使用 cakephp 主干 js 的经验。我也想在 CRUD cakephp 上使用它。
【问题讨论】:
标签: backbone.js routing cakephp-2.0 cakephp-3.0