【问题标题】:What's needed to add knockout.js to HotTowel?将 knockout.js 添加到 HotTowel 需要什么?
【发布时间】:2013-08-30 22:23:17
【问题描述】:

我在 VS 2012 中有一个使用 MVC4 和 HotTowel 模板的项目。

我尝试用 http://knockoutjs.com/examples/helloWorld.html 的 Hello World 示例替换 details.html 和 details.js。

所以 details.html 现在是:

<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>

还有 details.js:

 // Here's my data model
 var ViewModel = function(first, last) {
    this.firstName = ko.observable(first);
    this.lastName = ko.observable(last);

    this.fullName = ko.computed(function() {
        // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
        return this.firstName() + " " + this.lastName();
    }, this);
};

ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work

但现在我从详细信息页面中一无所获。导航块中的进度条只是停留在那里。

我一定错过了一些基本的东西。 HotTowel 中有什么我必须做的事情才能让它工作吗?

【问题讨论】:

  • 不确定其他地方是否存在热毛巾问题或拼写错误,但您在此处的代码在 jsfiddle.net/veHMb 上完美运行
  • 是的,它在 jsfiddle 中运行良好。我想知道在添加代码之前是否必须在 HotTowel 中做一些事情。

标签: knockout.js hottowel


【解决方案1】:

使用 F12 检查是否包含knockout.js。如果没有,只需包含它

<script type="text/javascript" src="{SOME_URL}knockout-2.3.0.js"></script>

【讨论】:

  • 谢谢,我认为 HotTowel 模板包含它。我可以在浏览器页面源码中看到
  • 如果你使用谷歌浏览器,请Ctrl+U查看源代码是否有knockout.js?如果有的话。使用 F12 查看 javascript 错误。
猜你喜欢
  • 2016-12-27
  • 1970-01-01
  • 1970-01-01
  • 2017-03-04
  • 2011-07-07
  • 2012-11-14
  • 2011-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多