0

I must not be using jsfiddle correctly. Because I am having problems with a more complex project I have decided to go back to the intro and see if there is something I missed. I am using PluralSight videos to get up to speed with knockout.

In the intro demo Steve Michelotti has a fiddle in which he is binding data in jquery prior to adding knockout. I can't seem to get this binding to work. The fiddle is here

  http://jsfiddle.net/SapphireGirl/Bdr55/2/

This is a very simple example and I would expect to see the Hello, bob in the run box but the name is not binding the the text in the view model even in jquery like it is shown in the demo.

He is using jquery 1.7 while I am using jquery 2.0 Why won't my name bind? Something silly I am sure.

javascript:

 $(function(){
var viewModel = {
    name: "bob",
    changeName: function() {
        this.name = "steve";

    }
};
ko.applyBindings(viewModel);

});

Thanks in advance

4

1 回答 1

0

你说

在介绍演示中,Steve Michelotti 有一个小提琴,他在添加淘汰赛之前在 jquery 中绑定数据。我似乎无法让这个绑定工作。

但在您的代码示例中,您明确引用ko- Knockout 对象。

问题是您想同时使用 JQuery 和 Knockout - 到目前为止,您已选择“JQuery 2.0”作为页面的框架,但您还没有在任何地方加载 Knockout。

转到左侧的“外部资源”部分,然后粘贴“ http://ajax.aspnetcdn.com/ajax/knockout/knockout-2.2.1.js”(Knockout CDN 网址之一 - 来自他们的下载页面)并按“+”将其添加到您的 jsfiddle。

按“运行”,现在一切正常。

于 2013-05-13T14:31:53.537 回答