我有以下看法:
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 函数放在哪里来监视选择更改事件,它都不会被调用。没有错误,似乎甚至没有调用 viewAttached 函数。对此的任何帮助表示赞赏。