javascript - Setting up Symfony2 and Backbone.js using Require.js -


i've got simple app, similar todo, entity called subject.

symfony2 serve rest api , backbone app take care of happens client-side. i've been trying set project require.js loads base model , set of simple views, error:

"networkerror: 404 not found - http://localhost:8000/bundles/pfiuser/js/app/.js" 

followed with

error: script error for: http://requirejs.org/docs/errors.html#scripterror in require.js line 166 

and timeout:

error: load timeout modules: http://requirejs.org/docs/errors.html#timeout 

i don't know require.js well, reckon comes 1 of defines doesn't work. here require's configuration (i've been basing work off this tutorial):

requirejs.config({     baseurl: '{{ asset('bundles/pfiuser/js/app/')  }}',     paths: {         text: "vendor/requirejs-text/text",         jquery: 'vendor/jquery/dist/jquery',         underscore: 'vendor/underscore/underscore',         backbone: 'vendor/backbone/backbone',         bootstrap: 'vendor/bootstrap/dist/js/bootstrap',         bootstrapeditable: 'vendor/bs3-editable/bootstrap-editable'     },     shim: {         underscore: {             exports: '_'     },     backbone: {          deps: ['underscore', 'jquery'],              exports: 'backbone'          },          bootstrap: {              deps: ['jquery'],              exports: 'bootstrap'          }     } }); 

and call app:

require([     '{{ asset('bundles/pfiuser/js/app/app.js')  }}' ], function(app){     app.initialize(); }); 

and that's in app.js gets weird. here base file:

define([     'jquery',     'underscore',     'backbone',     'router' ], function($, _, backbone, router){     var initialize = function(){         //router.initialize();     }      return {         initialize: initialize     }; }); 

there error. if comment router (which calls other files), still have error. if comment backbone call, don't have error anymore:

define([ 'jquery', 'underscore'/, 'backbone', 'router'/ ], function($, _, backbone, router){ var initialize = function(){ //router.initialize(); }

return {     initialize: initialize }; 

});

the error sounds mysterious me, have no idea how solve it. here's project directory structure reference:

//in src/pfi/userbundle/resources/public/js/ app/ |-- collections |      |-- subjects.js |-- models |      |-- subject.js |-- templates |      |-- subjects |      |     |-- list.html |-- vendor |     //all libraries installed via bower |-- views |      |-- subjects |             |-- list.js |-- app.js |-- boilerplate.js |-- main.js //(unused configure requirejs directly in page layout) |-- router.js 

i trying use require symfony2, think shouldn t do:

    require([     '{{ asset('bundles/pfiuser/js/app/app.js')  }}' ], function(app){     app.initialize(); }); 

more like

require([     'app' ], function(app){     app.initialize(); }); 

actually base url specifying path think, moreover, shouldn t have .js @ end. (i saw example twig filter |raw|escape '.js')


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -