我正在使用 Hot Towel Single Page Application 模板(使用 require、durandal、knout)。在这个特定的视图中,我使用的是 Twitter Bootstrap 切换选项卡,并且需要在用户首次进入视图时设置默认选定选项卡。我所拥有的不起作用。这是视图(CAApproval.html)-
<ul class="nav nav-tabs" style="width: 45%">
<li><a id="btnMyCert" href="#home" data-toggle="tab" data-bind="click: SelectMyCerts">My Certificates</a></li>
<li><a id="btnAll" href="#profile" data-toggle="tab" data-bind="click: SelectAllCerts">All Pending</a></li>
</ul>
这是视图模型(CAApproval.js)-
define(['services/logger', 'durandal/system', 'durandal/plugins/router', 'services/CertificateDataService'],
function (logger, system, router, CertificateDataService) {
var allCertificates = ko.observableArray();
var activate = function () {
logger.log('Certificate Approval View Activated', null, 'CA Approval', true);
$('#btnMyCert a[href="#home"]').tab('toggle');
// go get local data, if we have it
return CertificateDataService.getallCertificates(allCertificates);
};
var vm = {
activate: activate,
allCertificates: allCertificates,
title: 'Certificate Approvals',
SelectMyCerts: SelectMyCerts,
SelectAllCerts: SelectAllCerts
};
return vm;
function SelectAllCerts() {
return CertificateDataService.getallCertificates(allCertificates);
}
function SelectMyCerts() {
return CertificateDataService.getMyCertificates(allCertificates);
}
});
我什至尝试将这个 jQuery 直接放在视图中(没有用)-
<script type="text/javascript">
$(window).load(function () {
$('#tab a[href="#btnMyCert"]').tab('show');
});
</script>
我究竟做错了什么?