Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Nested use “Require.js” with "backbone.js"?
    primarykey
    data
    text
    <p>I'm doing the application, the use of backbone.js and require.js, I would like to achieve dynamic configuration module navigation by the "backbone.router" function, here is my question?</p> <p>This is my baserouter defined,I want to achieve dynamic load "backbone.view" according to "the viewPath" parameter.How can I do?</p> <pre><code>define(['require', 'underscore', 'backbone'], function(require, _, Backbone) { var BaseRouter = Backbone.Router.extend({ container: "#page", loadView: function(viewPath) { **//Here require lazy loading "base/people/view.js", ** **//I do not know how to achieve it?** var view = require(viewPath);//viewPath = "base/people/view"; this._currentView = new view(); this._currentView.render(); $(this.container).html(this._currentView.el); } }); return BaseRouter; }); </code></pre> <p>This is the definition of the router, it work with "baserouter" to dynamically set the navigation menu.</p> <pre><code>define(['baserouter'], function(baserouter) { //The JSON data should come from the database, //These data define the navigation information for all modules. var navs = JSON.parse('[{"name": "people","title": "peoplemanage","view": "base/people/view"},{"name": "test","title": "testmanage","view": "pub/test/view"}]'); var AppRouter = baserouter.extend(); for (var i = 0, l = navs.length; i &lt; l; i++) { var nav = navs[i]; AppRouter.prototype["loadView_" + nav.name] = function() { var path = nav.view; return function() { AppRouter.prototype.loadView(path); } }(); } var initialize = function() { var routes = {} for (var i = 0, l = navs.length; i &lt; l; i++) { var nav = navs[i]; routes[nav.name] = "loadView_" + nav.name; } var app_router = new AppRouter({ "routes": routes }); Backbone.history.start(); }; return { initialize: initialize }; }); </code></pre> <p>Here is the html code for the navigation menu:</p> <pre><code>&lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;a href="#people"&gt;people&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#test"&gt;test&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload