我正在尝试学习 knockOut.js,但无法真正起步。当我调用 ko.applyBindings 时,我的模型始终未定义。
我已经尝试过这里已经回答的解决方案。
我也在 jsFiddle 中尝试过:这里
我有以下 htm 表单:
<head>
<title>Mashup</title>
<script src="Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="Scripts/knockout-2.2.0.js" type="text/javascript"></script>
</head>
//html body
<script type="text/javascript">
$(window).load(function () {
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
}
var model = ko.applyBindings(new AppViewModel());
alert(model);
});
我也尝试过使用准备好的文档:
//I've also tried document ready but still not working.
$(document).ready(function () {
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
}
var model = ko.applyBindings(new AppViewModel());
alert(model);
});
我知道 ir 将是非常愚蠢的事情。有人可以帮忙吗?