I am currently writing what will be a very, very large one-page web / javascript application.
The technologies I use are ASP.NET MVC4, jquery, knockout.js and amplify.js.
The problem I encountered is that most, if not all sample applications for one page are for small applications, where all script templates (be it jquery, handlbars, etc.) are all in one file along with the rest of the html code. This is great for small applications, but the application I create is a whole logistic service program with many, many, many screens.
The approach that I have used so far, I have an outer shell (my main index.cshtml file), and I use the jquery load () method to load or rather inject the specific file that I need when the user makes a certain choice .
Example:
function handleLoginClick(){ App.mainContentContainer.delegate('#btnLogin', 'click', function() { App.loadModule('Home/ProductionControlMenu', App.MainMenuView.render()); }); }
here is the code for the App.loadModule function:
App.loadModule = function(path, callback){ App.mainContentContainer.load(App.siteRoot + path, callback); };
Everything went well until I actually had to interact with various form elements on a recently loaded screen. jquery doesn't seem to be able to deal with them directly. I can not use .live () or .delegate () because they are not events, these are text fields and buttons, and sometimes I need to change their css classes.
They only, what I found is to get the element descriptor from the outer shell (something that was not loaded via .load ()) and use the jquery.find () method as follows:
App.mainContentContainer.find('#btnLogin').addClass('disabled');
it’s clear that I don’t want to do something like this every time I need to interact or even retrieve values from a form element.
Does anyone have any ideas on how I can create a supported very large single-page application with potentially hundreds of .html files without having to have all this HTML in one file and still get around this .load () problem Eat me?
Any thoughts would be much appreciated. :-)
V / r
Chris
UPDATE
I thought I would post the update, as well as how it went and what worked. After much research, I decided to go with the Google AngularJS Javascript framework. This simplified the experiment exponentially, and I would definitely advise anyone looking for a great SPA to look.
References:
The main site is http://angularjs.org/
Amazing free short videos on Angular: http://www.egghead.io/