I have a page that I need grab the id from and pass them to the require.js module.
So the link to page is something like this: www.website.com/SomeController/SomeAction/Id
This page currently calls the require.js like this:
<script data-main="../Scripts/app/administrator/app.index" src="../Scripts/lib/require.js"></script>
Where app.index.js has the following code:
requirejs.config({
"baseUrl": "../Scripts/app/administrator",
"paths": {
"app.index": "app.index",
"ko": "../../lib/knockout-2.2.1",
'knockout.bindings': "../../lib/knockout.bindings",
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min",
"toastr": "../../lib/toastr",
"model.navigation" : "../models/model.navigation"
}
});
// Load the main app module to start the app
require(["main.index"], function (bs) { bs.run(); });
and the main.index.js has the following code:
define(['ko', 'indexViewModel', 'model.navigation'], function (ko, indexViewModel, Navigation) {
var
run = function () {
var vm = new indexViewModel();
var array = new Array();
$.getJSON("/api/navigations/getmynavigation/", function (data) {
$.each(data, function (key, val) {
var n = new Navigation();
n.navigationId(val.NavigationId);
n.name(val.Name);
array.push(n);
});
}).done(function(){
vm.navigations(array);
});
ko.applyBindings(vm, document.getElementById('#administrator-home-view'));
};
return {
run: run
};
});
What I am confused about is that if I want to pass an parameter to this module, how do I do that?
The parameter's source could come from:
- Anchor:
<a href="/administrator/user/3>Bob</a>
- Server Side: return View(3)
Either way how is it done in require.js?