我是 SammyJS 的新手。我正在尝试使用 SammyJS 和 KnockoutJS 创建一个示例应用程序。我正在创建一些运行时 HTML 并添加绑定属性,但淘汰绑定无法使用它。
var priorities = { Low: 0, Important: 1, Medium: 2, High: 3, VeryHigh: 4 };
var mailBoxViewModel = function () {
var self = this;
self.heading = 'Learn Sammy JS';
self.Messages = ko.observableArray([{ Id: 1, Message: 'Hello', Description: '', Sender: { Name: 'Ravi', SentOn: new Date(), Priority: priorities.Low} }, { Id: 2, Message: 'Meeting', Description: '', Sender: { Name: 'Chandar', SentOn: new Date(), Priority: priorities.High}}]);
var routes = $.sammy(function () {
this.element_selector = '#content';
this.before(function () {
this.swap('');
});
this.get("#/Messages", function (context) {
var div = $("<div class='well'></div>");
div.append("<h1 data-bind='text:heading'></h1>");
var table = $("<table class='table' ></table>");
table.append("<thead><tr><th>Messages</th></tr></thead>");
table.append("<tbody data-bind='foreach: Messages'><tr><td data-bind='text:Message'></td></tr></tbody>");
div.append(table);
context.$element().append(div);
});
this.get("#/Sent", function (context) {
var div = $("<div class='well'></div>");
var table = $("<table class='table'></table>");
table.append("<thead><tr><th>Messages</th></tr></thead>");
table.append("<tbody><tr><td>Hello World</td></tr></tbody>");
div.append(table);
context.$element().append(div);
});
});
$(function () {
routes.run("#/Messages");
});
};
ko.applyBindings(new mailBoxViewModel());