Javascript 未捕获错误:组件';设置';:未知模板值:[对象]
我尝试使用敲除组件。我使用requirejs将库加载到我的代码中,但每当我这样做时,就会出现以下错误:Javascript 未捕获错误:组件';设置';:未知模板值:[对象],javascript,knockout.js,components,Javascript,Knockout.js,Components,我尝试使用敲除组件。我使用requirejs将库加载到我的代码中,但每当我这样做时,就会出现以下错误: Uncaught Error: Component 'settings': Unknown template value: [object Object] 这是组件的代码: define( [ "knockout", "text!./settings.html", "underscore", "../../compone
Uncaught Error: Component 'settings': Unknown template value: [object Object]
这是组件的代码:
define(
[
"knockout",
"text!./settings.html",
"underscore",
"../../components/models/tabbed-navigation/tabsNavigationConfig",
"../../components/models/tabbed-navigation/tabitemConfig"
],
function(ko, settingsTemplate, _) {
var isInitialized = false;
var tabsNavigationInstance = null;
function settingsViewModel(params) {
var self = this;
self.tabbedNavigation = new ko.observable();
if(!isInitialized) {
isInitialized = true;
tabsNavigationInstance = init(params);
}
self.tabbedNavigation(tabsNavigationInstance);
self.route = new ko.observable();
if(params.tab) {
self.route(params.request_);
}
return self;
};
function init(params) {
var newTabs = [];
for(var i = 0; i < 5; i++) {
var key = 'tab' + i;
newTabs.push(new tabitemConfig(
"Settings " + i,
"/settings/" + key,
key == params.tab,
'greeter'));
}
tabsNavigationInstance = new tabsNavigationConfig(newTabs, 0);
return tabsNavigationInstance;
}
return {
viewModel: settingsViewModel,
template: settingsTemplate
};
});
这是settings.html的内容:
<div>
<h1>Settings</h1>
</div>
<tabbed-navigation params="tabConfig : tabbedNavigation(), route: route()">
</tabbed-navigation>
如何对此进行故障排除?我的代码中有什么明显的错误吗?我跟踪敲除的源代码。丢失设置页面时,模板配置不正确。我检查startup.js的代码。法典
ko.components.register(app.pages.settings.name, {
template: {
require: app.pages.settings.template
}
});
应该是
ko.components.register(app.pages.settings.name, {
require: app.pages.settings.template
});
define(['jquery', 'knockout', './router', 'app/app', 'bootstrap', 'knockout-projections'], function($, ko, router) {
ko.components.register(app.components.greeter.name, {
require: app.components.greeter.template
});
ko.components.register(app.pages.home.name, {
require: app.pages.home.template
});
ko.components.register(app.pages.settings.name, {
template: {
require: app.pages.settings.template
}
});
ko.components.register(app.components.tabitem.name, {
require: app.components.tabitem.template
});
ko.components.register(app.components.tabbedNavigation.name, {
require: app.components.tabbedNavigation.template
});
ko.applyBindings({
route: router.currentRoute
});
});
ko.components.register(app.pages.settings.name, {
template: {
require: app.pages.settings.template
}
});
ko.components.register(app.pages.settings.name, {
require: app.pages.settings.template
});