我希望从http://www.bootstrapcdn.com/#bootswatch_tab应用引导主题。
所以我有 View Model : Shell 和 VIew ,如下所示,我正在使用 Ko.Observable 数组加载所有需要在 Bootstrap Drop-down 中显示的主题名称,但 Drop-down 没有填充可观察值
请帮我解决。提前致谢
外壳.js
define(['durandal/system', 'plugins/router', 'services/logger'],
function (system, router, logger , config) {
var themes = ko.observableArray([
{ key: "amelia", text: "Amelia" },
{ key: "cerulean", text: "Cerulean" },
{ key: "cosmo", text: "Cosmo" },
{ key: "cyborg", text: "Cyborg" },
{ key: "flatly", text: "Flatly" },
{ key: "journal", text: "Journal" },
{ key: "readable", text: "Readable" },
{ key: "simplex", text: "Simplex" },
{ key: "slate", text: "Slate" },
{ key: "spacelab", text: "Spacelab" },
{ key: "united", text: "United" }
]);
var shell = {
activate: activate,
router: router,
themes: themes
};
return shell;
//#region Internal Methods
function activate() {
return boot();
}
function boot() {
log(config.appTitle + 'Loaded!', null, true);
router.on('router:route:not-found', function (fragment) {
logError('No Route Found', fragment, true);
});
var routes = [
{ route: '', moduleId: 'home', title: 'Home', nav: 1 },
{ route: 'details', moduleId: 'details', title: 'Details', nav: 2 }];
return router.makeRelative({ moduleId: 'viewmodels' }) // router will look here for viewmodels by convention
.map(routes) // Map the routes
.buildNavigationModel() // Finds all nav routes and readies them
.activate(); // Activate the router
}
function log(msg, data, showToast) {
logger.log(msg, data, system.getModuleId(shell), showToast);
}
function logError(msg, data, showToast) {
logger.logError(msg, data, system.getModuleId(shell), showToast);
}
//#endregion
});
查看 Shell.html
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="/">
<span class="title">Hot Towel SPA</span>
</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav" data-bind="foreach: router.navigationModel">
<li data-bind="css: { active: isActive }">
<a data-bind="attr: { href: hash }, text: title"></a>
</li>
</ul>
<!-- Load Themes -->
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Themes <b class="caret"></b></a>
<ul class="dropdown-menu" id="themes" data-bind="foreach: themes">
<li>
<a data-bind="attr: { href: hash }, text: text"></a>
</li>
</ul>
</li>
</ul>
<div class="loader pull-right" data-bind="css: { active: router.isNavigating }">
<div class="progress progress-striped active page-progress-bar">
<div class="progress-bar" style="width: 100px;"></div>
</div>
</div>
</div>
</div>
</div>