我对此感到有些困惑,因为我确信所有变量在运行时之前都会被带到 javascript 的“顶部”,然后从那里处理。
所以我的错误
TypeError: hutber.portfolio.ko is undefined
[Break On This Error]
items: ko.observableArray(hutber.portfolio.ko.data),
目的
(function ($) {
"use strict"; //For good development standards :)
hutber.portfolio = {
init: function(){
e(typeof(hutber));
hutber.portfolio.changeOptionsBoxHeight();
//Bind the height resize in window resize
$(window).resize(function(){
hutber.portfolio.changeOptionsBoxHeight();
});
//start KO
hutber.portfolio.ko.init();
},
changeOptionsBoxHeight: function(){
var height = $(window).height();
$('.portfolio--options').height(height-400);
}
};
hutber.portfolio.ko = {
init: function(){
ko.applyBindings(new hutber.portfolio.ko.portfolioViewModel());
},
data: [],
items: ko.observableArray(hutber.portfolio.ko.data),
portfolioViewModel: function(){
hutber.portfolio.ko.items = ko.observableArray(hutber.portfolio.ko.data);
$.getJSON('/js/pages/portfolio.json').done(function(info){
hutber.portfolio.ko.data = info;
hutber.portfolio.ko.items (hutber.portfolio.ko.data);
});
}
};
hutber.portfolio.init();
})(jQuery);
我真的很想把它上传到小提琴,但由于某种原因,我在他们的网站上遇到了 js 错误。我相信我的防火墙阻止了某些文件的加载。