Я попытался использовать Knockout с требованием js, но я не смог связать данные с viewmodel.RequireJs с нокаутом
HTML
<!doctype html>
<html lang="en">
<head>
<title>SPA</title>
<!-- Load the script "js/main.js" as our entry point -->
<script data-main="js/app" src="js/lib/require.js"></script>
</head>
<body>
Today's message is: <span data-bind="text: myMessage"></span>
</body>
</html>
app.js
requirejs.config({
"baseUrl": "js/lib",
"paths": {
"app": "../app",
"jquery": "jquery",
"knockout-3.4.0":"knockout-3.4.0",
"custom":"../custom/custom-script",
"customKO":"../custom/custom-knockout"
}
});
require(['knockout-3.4.0', 'customKO'], function(ko, appViewModel) {
ko.applyBindings(new appViewModel());
});
// Load the main app module to start the app
requirejs(["app/main"]);
main.js
define(["jquery", "knockout-3.4.0", "jquery.alpha", "jquery.beta" , "custom" , "customKO"], function($ , ko) {
//the jquery.alpha.js and jquery.beta.js plugins have been loaded.
$(function() {
$('body').alpha().beta();
});
});
custon-knockout.js
//Main viewmodel class
define(['knockout-3.4.0'], function(ko) {
return function appViewModel() {
var viewModel = {
myMessage: ko.observable() // Initially blank
};
viewModel.myMessage("Hello, world!"); // Text appears
};
});
, но я получаю ошибку ниже
Uncaught ReferenceError: Невозможно обработать переплета "текст: функция() {возвращение MyMessage}" сообщение: MyMessage не определено