2011-08-13 73 views
0

http://net.tutsplus.com/tutorials/javascript-ajax/into-the-ring-with-knockout-js/KnockJS和JQuery教程assitance需要

我努力回合2 - 創建視圖,使用公佈在網站上的代碼,我被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);

行爲

(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", 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); 

回答

1

在教程中的代碼是有缺陷的。 actions.js代碼在viewModel和ko.applyBindings之間有一個額外的括號。它看起來像這樣:

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

它必須看起來像這樣:

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

我不喜歡這個樣品幾件事情。這裏是我的版本,稍作修改:

(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

謝謝,你可以藉助你的智慧調試,因爲什麼都沒有返回到錯誤控制檯或提醒? – Wasabi

+0

這仍然不適合你?你有所有合適的js文件嗎? – kakridge

+0

它在工作,但想知道你是否藉助你的調試洞察力,或者這是你已經熟練使用的東西。 – Wasabi