【发布时间】:2014-09-22 05:45:10
【问题描述】:
我使用的是 durandal 1.1 版。从撰写绑定我通过activationData 传递一些额外的参数。但是子视图模型没有得到值。在 activate 方法中总是以未定义的形式接收。
<div data-bind="compose: {
model: 'testmodel',
activationData: {data : 10},
activate: true
}">
</div>
activate 方法如下:
define(['durandal/app', 'durandal/system', 'durandal/plugins/router', 'services/logger', 'services/datacontext', 'config'], function (app, system, router, logger, Datacontext, config) {
var testmodel= function () {
var vm = this;
vm.activate = function (activationData) {
alert(activationData);
logger.log('View Activated',
null, 'test', true);
};
};
return testmodel;
});
还向原型添加了激活,但这也不起作用:
define(['durandal/app', 'durandal/system', 'durandal/plugins/router', 'services/logger', 'services/datacontext', 'config'], function (app, system, router, logger, Datacontext, config) {
var testmodel= function () {
var vm = this;
};
testmodel.prototype.activate = function (activationData) {
alert(activationData);
logger.log('View Activated',
null, 'test', true);
};
return testmodel;
});
【问题讨论】:
-
是的,它在 2.1 中可用。 Reference.
-
@Brett 在 durandal 1.1 中,当我看到 viewModel.js 文件时,我看到activationData 被传递给了 activate 方法。这意味着它在 1.1 中可用?我说的对吗?
-
只是猜测,但我认为您使用它的方式是错误的。可能是它不理解
{ data: 10 }的字面意思。您是否尝试过10之类的值或尝试在表达式周围加上单引号? -
@Brett 是的,我尝试传递 activationData : [10] / activationData : 10。这没有帮助。
-
@user2585299
vm来自哪里?应该是vm.prototype.activate吗?或者,如果这是一个单例模块,则需要导出activate。
标签: knockout.js durandal hottowel