本文介绍了ActivationData没有在durandal中传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用durandal 1.1版.从组合绑定中,我通过ActivationData传递了一些额外的参数.但是子视图模型没有获得该值.始终在activate方法中以未定义的形式接收它.

I am using durandal version 1.1. From compose binding I am passing some extra parameters through activationData. But the child viewmodel does not get the value. It is always received as undefined in the activate method.

<div data-bind="compose: {
                        model: 'testmodel',
                        activationData: {data : 10},
                            activate: true

                        }">

</div>

activate方法如下:

The activate method looks like:

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;

});

还在原型中添加了激活功能,但效果不佳:

Also added activate to prototype but that does not work as well:

 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;

});

推荐答案

我解决了这个问题.我正在使用durandal 1.1版本. composition.js 文件中有一个 tryActivate 函数,该函数将进行如下所示的调用:

I solved the problem. I am using durandal 1.1 version. There is a tryActivate function in composition.js file which makes a function call as shown below:

function tryActivate(settings, successCallback) {
    if (shouldPerformActivation(settings)) {
        viewModel.activator().activateItem(settings.model).then(function (success) {
            if (success) {
                successCallback();
            }
        });
    } else {
        successCallback();
    }
}

仅将viewmodel参数传递到ActivateItem,如上所示.我还从那里传递了ActivationData参数,如下所示:

Only viewmodel parameter was passed to activateItem as seen above. I also passed the activationData parameter from there as below:

viewModel.activator().activateItem(settings.model,settings.activationData).then(function (success) {
            if (success) {
                successCallback();
            }
        });

现在,在问题中看到的testmodel中的activate方法将在activationData参数中获取值10.

Now, the activate method in testmodel as seen in the question gets the value 10 in activationData parameter.

这篇关于ActivationData没有在durandal中传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 04:44