【发布时间】:2012-06-14 08:13:40
【问题描述】:
我正在寻找使用Backbone.Marionette、Backbone.Router 和Requirejs 引导我的网络应用程序的最佳方式。
以下实现有效,但我想知道这是否是正确的制作方法。
这是我的一些代码 (*)。
我的问题是:
1)对以下数据流(index.html -> conf.js -> router.js -> app.js)?
2)每个区域的Backbone.View(header,sidebar.....)应该根据上下文在router.js或app.js或展位中实例化?
// index.html
<!doctype html>
<html lang="en">
<head>
<!-- Load the script "/js/conf.js" as our entry point -->
<script data-main="js/conf" src="js/vendor/require.js"></script>
</head>
<body>
</body>
// js/config.js
require.config({
// some code
});
require(['app']); // instead of require(['conf']);
// router.js
define([
'app',
// others modules
],
function(App, $, _, Backbone, Marionette){
"use strict";
var AppRouter = Backbone.Marionette.AppRouter.extend({
routes: {
test: test,
"*defaults": "home"
}
var initialize = function ()
{
var app_router = new AppRouter;
};
return {
initialize: initialize
};
});
// js/app.js
define(
[
// some modules
],
function ($, _, Backbone, Router, Mustache, Layout, SidebarView) {
var MyApp = new Backbone.Marionette.Application();
MyApp.addInitializer(function () {
$('body').html(Layout);
MyApp.addRegions({
header: '#header',
sidebar: '#sidebar',
mainColumn: '#main-column',
rightColumn: '#right-column'
});
});
MyApp.addInitializer(function () {
var sidebarView = new SidebarView();
MyApp.sidebar.show(sidebarView);
});
MyApp.on("initialize:after", function () {
// Router.initialize();
});
MyApp.start();
return MyApp;
});
【问题讨论】:
标签: backbone.js marionette backbone-routing