2016-11-30 91 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