我有一個頁面,我需要從中獲取id並將它們傳遞給require.js模塊。將參數傳遞給Require.js模塊
所以鏈接到頁面是這樣的:www.website.com/SomeController/SomeAction/Id
本頁目前調用require.js這樣的:
<script data-main="../Scripts/app/administrator/app.index" src="../Scripts/lib/require.js"></script>
在哪裏app.index.js有以下代碼:
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(); });
和main.index.js具有下面的代碼:
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
};
});
我很困惑的是,如果我想傳遞一個參數到這個模塊,我該怎麼做?
參數的來源可能來自:
- 主持人:
<a href="/administrator/user/3>Bob</a>
- 服務器端:返回查看(3)
無論哪種方式,它是如何在require.js做了什麼?