开发者

KnockJS and JQuery Tutorial assitance needed

开发者 https://www.devze.com 2023-03-28 03:44 出处:网络
http://net.tutsplus.com/tutorials/javascript-ajax/into-the-ring-with-knockout-js/ I\'ve worked to Round 2 – Creating a View, using the code as published on the site, I\'m returned an error by FF FB

http://net.tutsplus.com/tutorials/javascript-ajax/into-the-ring-with-knockout-js/

I've worked to Round 2 – Creating a View, using the code as published on the site, I'm returned an error by FF FB 1.7.3

Error: missing ) in parenthetical Source File: http://testing:8888/knockout/js/behavior.js Line: 7, Column: 3 Source Code: }; ko.applyBindings(viewModel);

Behavior

(function ($) { var model = [{  name: "John",  address: "1, a road, a town, a county, a postcode",  tel: "1234567890",  site: "www.aurl.com", pic: "/i/john.jpg",  deleteMe: function () { viewModel.people.remove(this); }
}, {  name: "Jane",  address: "2, a street, a city, a county, a postcode",  tel: "1234567890", 开发者_JAVA百科 site: "www.aurl.com",  pic: "/i/jane.jpg",  deleteMe: function () { viewModel.people.remove(this); }
}, {  name: "Fred",  address: "3, an avenue, a village, a county, a postcode",  tel: "1234567890",  site: "www.aurl.com",  pic: "/i/fred.jpg",  deleteMe: function () { viewModel.people.remove(this); }
}, {  name: "Freda",  address: "4, a street, a suburb, a county, a postcode",  tel: "1234567890",  site: "www.aurl.com",  pic: "/i/jane.jpg",  deleteMe: function () { viewModel.people.remove(this); }
}], viewModel = { people: ko.observableArray(model),
} }; ko.applyBindings(viewModel); })(jQuery);


The code on the tutorial is flawed. The behaviors.js code has an additional bracket between viewModel and ko.applyBindings. It looks like this:

viewModel = { people: ko.observableArray(model),
} }; ko.applyBindings...

It needs to look like this:

viewModel = { people: ko.observableArray(model),
}; ko.applyBindings...

I didn't like several things about this sample. Here is my version, slightly modified:

(function ($) { 
    var model, viewModel;
    model = [
        {
           name:"John",
           address:"1, a road, a town, a county, a postcode",
           tel:"1234567890",
           site:"www.aurl.com",
           pic:"/img/john.jpg",
           deleteMe:function ()   {
              viewModel.people.remove(this);
           }
        },
        {
           name:"Jane",
           address:"2, a street, a city, a county, a postcode",
           tel:"1234567890",
           site:"www.aurl.com",
           pic:"/img/jane.jpg",
           deleteMe:function ()   {
              viewModel.people.remove(this);
           }
        },
        {
           name:"Fred",
           address:"3, an avenue, a village, a county, a postcode",
           tel:"1234567890",
           site:"www.aurl.com",
           pic:"/img/fred.jpg",
           deleteMe:function ()   {
              viewModel.people.remove(this);
           }
        },
        {
           name:"Freda",
           address:"4, a street, a suburb, a county, a postcode",
           tel:"1234567890",
           site:"www.aurl.com",
           pic:"/img/jane.jpg",
           deleteMe:function ()   {
              viewModel.people.remove(this);
           }
        }
    ];
    viewModel = {
        people: ko.observableArray(model)  
    } ; 
    ko.applyBindings(viewModel);  
})(jQuery);
0

精彩评论

暂无评论...
验证码 换一张
取 消