我想學習knockOut.js並且不能真正離開地面。當我調用ko.applyBindings時,我的模型總是未定義的。爲什麼Knockout.js不能綁定
我試過已經回答的解決方案here。
我也試圖在的jsfiddle:here
我有以下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會是一件非常愚蠢的事情。任何人都可以幫忙嗎?
感謝您的+1 – davy