我遇到了敲除映射插件的问题,该插件显示了可观察的功能代码而不是绑定中的展开值。 它只发生在我从互联网上获取knockout.js,如果我使用我的本地副本knockout.js它工作正常。
index.html
--------------
<DOCTYPE HTML>
<html>
<head>
<title>Require Demo</title>
<script type="text/javascript" data-main="scripts/main.js" src="scripts/require.js"></script>
</head>
<body>
<div id="vm1" data-bind="text: timeWhenLoaded"></div>
<div id="vm2" data-bind="text: timeWhenLoaded"></div> <!-- Issue: shows code of observable function, not the value -->
</body>
</html>
scripts/main.js
---------------------
require.config({
baseUrl: 'scripts/lib',
paths: {
app: '../app',
helper: '../helper'
}
});
require(["https://github.com/knockout/knockout/releases/download/v3.0.0/knockout-3.0.0.debug.js", "knockout.mapping", "helper/utils"], function(knockout, mapping, utils) {
//require(["knockout", "knockout.mapping", "helper/utils"], function(knockout, mapping, utils) { // works fine
console.log('time when loaded: ' + utils.timeWhenLoaded());
function _vm () {
this.timeWhenLoaded = knockout.observable(utils.timeWhenLoaded());
}
var vm1 = new _vm();
var vm2 = mapping.fromJS({
timeWhenLoaded: utils.timeWhenLoaded()
});
knockout.applyBindings(vm1, document.getElementById('vm1'));
knockout.applyBindings(vm2, document.getElementById('vm2'));
});
scripts/helper/utils.js
------------------------------
define(function(){
var now = Date.now();
function timeWhenLoaded() {
return new Date(now).toString();
}
return {
timeWhenLoaded: timeWhenLoaded
};
});
scripts/lib/knockout.js
scripts/lib/knockout.mapping.js