【发布时间】:2017-11-22 12:23:28
【问题描述】:
当我使用敲除组件时,出现绑定错误。 HTML:
<html >
<head>
<link rel="stylesheet" href="css/default.css">
</head>
<body>
<main id="shell">
<!-- logo & top level links -->
<header>
<header-widget></header-widget>
</header>
</main>
<script type="text/javascript" src="thirdparty/requirejs/require-2.3.3.js" data-main='./js/requirejs.config'></script>
</body>
java脚本:
var requireConfig = {
baseUrl: './',
paths: {
jquery: 'thirdparty/jquery/jquery-1.11.2',
ko: 'thirdparty/knockout/knockout-3.4.2',
text: 'thirdparty/requirejs/text'
},
shim: {
}
};
require.config(requireConfig);
define(
function(require) {
require(['jquery', 'ko'], function($, ko) {
var modle = {
};
$(document).ready(function() {
ko.components.register('header-widget', {
viewmodel: function(params){
this.username = ko.observable('tom');
},
template: '<div data-bind="text:username">userxxx</div>'
});
ko.applyBindings(modle);
});
});
}
);
我检查了名称,它们是正确的。我无法弄清楚绑定失败的原因。我查看了 stackoverflow.com,但找不到与此相同的问题。您能帮帮我吗?
【问题讨论】:
标签: javascript knockout.js components