0

ノックアウト2.1.0を使用したノックアウトは初めてです。外部 Java スクリプト ファイルがありますが、html ファイルで呼び出されません。私は理解できない。

私は自分のhtmlファイルに以下を追加しました

  <script src="Scripts/TestJavascript.js"></script>

JS ファイル

///<reference path="~/Scripts/jquery-1.8.1.min.js">
///<reference path="~/Scripts/knockout-2.1.0.debug.js">
$(function AppViewModel() {
this.firstName = ko.observable("rash");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function(){
    return this.firstName() + " " + this.lastName();
}, this);
})
ko.applyBindings(new AppViewModel());

ありがとう。

4

2 に答える 2

5

ViewModel を作成していません。あなたはそれをjqueryに渡しています。

試す

var AppViewModel = function() {
  this.firstName = ko.observable("rash");
  this.lastName = ko.observable("Bertington");
  this.fullName = ko.computed(function(){
      return this.firstName() + " " + this.lastName();
  }, this);
})
ko.applyBindings(new AppViewModel());
于 2012-09-17T13:56:34.690 に答える
1

this code must appear either after the bound html, or within a document ready event (jquery)

function AppViewModel() {
    this.firstName = ko.observable("rash");
    this.lastName = ko.observable("Bertington");
    this.fullName = ko.computed(function(){
        return this.firstName() + " " + this.lastName();
    }, this);
};
ko.applyBindings(new AppViewModel());
于 2012-09-17T13:57:18.013 に答える