2016-11-30 46 views
0

我是新來的淘汰賽,看過帖子廣泛,但不能簡單的例子,在Visual Studio 2015年運行knockoutjs的hello world將不會運行

總是得到所有的HTML標籤標記爲類型或命名空間的問題調試器,當運行時,我看到空箱子。

下面是代碼:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title> Home Page</title> 
    <script type='text/javascript' src='jquery-1.10.2.min.js'></script> 
    <script type='text/javascript' src='knockout-20.3.0.debug.js'></script> 
</head> 
<body> 
    <p>First name: <input data-bind="value: firstName" /></p> 
    <p>Last name: <input data-bind="value: lastName" /></p> 
    <h2>Hello, <span data-bind="text: fullName"> </span>!</h2> 

<script type="text/javascript"> 
    // Here's my data model 
    function viewModel() { 
     this.firstName = ko.observable('Planet'); 
     this.lastName = ko.observable('Earth'); 
     this.fullName = ko.computed(function() { 
      // Knockout tracks dependencies automatically. 
      return this.firstName() + " " + this.lastName();},this); 
     }; 

    ko.applyBindings(viewModel()); // This makes Knockout get to work 
</script> 
</body> 
</html> 
+0

請添加更多上下文。什麼是您使用的項目模板?你的項目/解決方案結構如何? – rawel

+3

你確定淘汰賽腳本版本「knockout-20.3.0」嗎?或者它應該是'knockout-2.3.0'? – gkb

回答

1

我檢查你比如它工作正常,如果把基因敲除的正確版本。我把更老的版本。請檢查你的淘汰賽腳本src,我希望這會對你有所幫助。

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title> Home Page</title> 
     <script type='text/javascript' src='https://code.jquery.com/jquery-1.10.2.min.js'></script> 
     <script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/knockout/2.0.0/knockout-debug.js'></script> 
    </head> 
    <body> 
     <p>First name: <input data-bind="value: firstName" /></p> 
     <p>Last name: <input data-bind="value: lastName" /></p> 
     <h2>Hello, <span data-bind="text: fullName"> </span>!</h2> 

     <script type="text/javascript"> 
      // Here's my data model 
      function viewModel() { 

       this.firstName = ko.observable('Planet'); 
       this.lastName = ko.observable('Earth'); 
       this.fullName = ko.computed(function() { 
        // Knockout tracks dependencies automatically. 
        return this.firstName() + " " + this.lastName();},this); 
       }; 

      ko.applyBindings(new viewModel()); 
     </script> 
    </body> 
</html> 
+0

只是爲了澄清在OP中viewModel沒有被新的操作符調用 – Jonathan