0
把一个非常简单的Knockout.js例子放在一起来学习它是如何工作的。为什么简单的knockout.js无限加载默认视图?
我立即意识到它无限加载并导致浏览器做一个计算器。基本上,它运行默认的runRoute并且不会停止!
一个的jsfiddle你可以充分见证和使用调试器检查:http://jsfiddle.net/hn5JS/
的基本代码:
function AlloyViewModel() {
// Data
var self = this;
self.appViews = ['Dashboard', 'Engine', 'Map', 'Jobs', 'Clients', 'Users'];
self.currentAppView = ko.observable();
// Behaviours
self.goToAppView = function(appView) {
location.hash = '/' + appView;
};
// Client-side routes
Sammy(function() {
this.get('#/:folder', function() {
self.currentAppView(this.params.appView);
});
this.get('', function() { this.app.runRoute('get', '#Dashboard') });
}).run();
};
ko.applyBindings(new AlloyViewModel());
这是sammy.js或者我自己的代码的问题吗?我需要使用不同版本的jQuery吗?谢谢您的帮助。