我想讓KO Grid工作。我在Ko 2.1環境中,我試圖在MVC視圖中使用Ko網格。奇怪的是,當我加載我的頁面時,我根本沒有看到任何問題。我有一個小提琴文件,它使得frid絕對沒問題:http://jsfiddle.net/jearles/sf4p3/14/KOGrid沒有顯示
我的代碼非常相似:但是根本沒有渲染。
我的HTML是如下:
<div id="KoGridContainer">
<div data-bind="koGrid: { data: Prizefillfilmentstatuses }"></div>
<button id="Get" data-bind="click:GetAll">Get</button>
<p><span data-bind='text: Prizefillfilmentstatuses().length'> </span> row(s)</p>
</div>
和我的JS代碼看起來如下:
function ($, ui, ko, komapping, servicesConfig, constants, koGrid) {
$("#body").fadeIn();
var self = {};
self.ViewModel = {
GetAll: function() {
self.getAll();
},
Prizefillfilmentstatuses: ko.observableArray([
{ id: 1, firstName: 'John', lastName: 'Doe', createdOn: '1/1/2012', birthday: '1/1/1977', salary: 40000 },
{ id: 1, firstName: 'Jane', lastName: 'Harper', createdOn: '1/2/2012', birthday: '2/1/1976', salary: 45000 },
{ id: 1, firstName: 'Jim', lastName: 'Carrey', createdOn: '1/3/2012', birthday: '3/1/1985', salary: 60000 },
{ id: 1, firstName: 'Joe', lastName: 'DiMaggio', createdOn: '1/4/2012', birthday: '4/1/1991', salary: 70000 },
{ id: 1, firstName: 'Jeff', lastName: 'Saturday', createdOn: '1/5/2012', birthday: '5/1/1998', salary: 65000 },
{ id: 1, firstName: 'Marg', lastName: 'Simpson', createdOn: '1/6/2012', birthday: '6/1/1921', salary: 20000 },
{ id: 1, firstName: 'Tim', lastName: 'Allen', createdOn: '1/7/2012', birthday: '7/1/1977', salary: 35000 },
{ id: 1, firstName: 'Kevin', lastName: 'Bacon', createdOn: '1/8/2012', birthday: '8/1/1977', salary: 30000 },
{ id: 1, firstName: 'Jack', lastName: 'Murphy', createdOn: '1/9/2012', birthday: '9/1/1999', salary: 55000 },
{ id: 1, firstName: 'Jessica', lastName: 'Smith', createdOn: '1/10/2012', birthday: '10/1/1979', salary: 45000 }
])
};
// if ($("#KoGridContainer").length == 1) {
// $.consolelog("found Ko-Grid");
// ko.applyBindings(self.ViewModel, $("#KoGridContainer").get(0));
// }
ko.applyBindings(self.ViewModel);
當然它不是整個文件。我剛把我的視圖模型和綁定在那裏。現在,最有趣的事實是,控制檯根本沒有錯誤,並且它還向我顯示了網格的3-4次。我很難過地說「隨機」。我嚴重無法追查它曾經出現的情況,但它已經顯示我網格的1%的時間。其他99%沒有電網。
任何想法?
對此有點更新。我將Fiddle中的代碼複製並粘貼到我的環境中,並再次無法顯示網格。這絕對是一件奇怪的事情。 – TeaLeave