Hello so I'm working on an .Net single page application using Knockoutjs, Sammy.js, and Rest Web API. I'm somewhat new to these libraries and I've run into a few core design issues and I'm hoping to gain some insight.
The main issue I have is using knockouts ko.applybinding targeted at specific elements.
this.get("#/Classroom", function(context) {
dataPack.build(PageLoc, context)
appPres.reload();
ko.applyBindings(new classroomVmCore.View(), document.getElementById('view-Classroom'));
});
Since this is a single page application I have to dynamically append my views. The dataPack.build is what grabs my view and binds to the context of the single page. That functionality works fine as expected, but when it comes to ko.applyBindings I find the following issues occur..
Any page refresh loses my view model and if the
sammy.jshash isn't hit the data is missing. This problem mainly occurs for any shared content (ex. navigation items, layout items, etc) Since this data has its own view model when I hit the#/Classroomhash again those shared models are lost.Is their another option besides using the constructor function below for my view model? Setting that to a variable and then trying to adjust or add to that variable doesn't seem to adjust my model.
I'm essentially looking for a way to update/refresh my model at any time so I can handle a page fresh.
Has anyone used these libraries for an SPA run into these issues? How did you structure your views and bindings?
Any help or ideas are greatly appreciated.
I've created my own site (not plugging here, see profile if you desire) as a SPA with knockout. I actually use templates to achieve my goal. This is a shortend example of how I do it.
Sorry, I've never used sammy.js to have anything to say about that.