我有以下观点:
define(['durandal/http','plugins/router','knockout'], function (http,router,ko) {
function actionItem(data) {
var self = this;
self.ActionID = data.ActionID;
self.Heading = data.Heading;
}
function viewModel() {
var self = this;
self.Actions = ko.observableArray([]);
self.People = [
'My Actions',
'Everyones Actions'
];
self.Whats = [
'Outstanding Actions',
'Completed Actions',
'All Actions'
];
self.Hows = [
'Entry',
'Alphabetical',
'Deadline'
];
self.activate = function () {
return http.ajaxRequest("get", "/api/actions/getactions?who=" + self.People[0] + "&what=" + self.Whats[0] + "&how=" + self.Hows[0])
.done(function (allData) {
var mapped = $.map(allData, function (list) { return new actionItem(list); });
self.Actions(mapped);
});
};
self.viewAttached = function () {
$("#cboWhat").change(function () {
alert("test");
});
};
}
var model = new viewModel();
return model;
});
页面正常工作,数据从激活功能加载,但无论我把jQuery函数用于监视select变更事件,它都不会被调用。没有错误,似乎甚至没有调用viewAttached函数。对此有任何帮助表示赞赏。
答案 0 :(得分:1)
对于遇到同一问题的任何人来说,似乎Durandal的版本2不使用viewAttached而是简单地附加。改变了self.viewAttached到self.attached和所有工作。
此外,navigateTo现在只需在版本2中导航。