如何在Durandal建立亲子关系?

时间:2013-09-09 10:27:31

标签: javascript durandal

我正在尝试在Durandal中设置SPA,我需要将JavaScript对象从一个视图传递到另一个视图。我读过关于亲子关系的文章,我创建了一个(或者至少我认为我做了......)但由于某种原因它没有用...我花了好几个小时试图找到解决方案,但就我而言我正在做这件事。这是代码:

第一个观点:

<h3>List of candidates:</h3>
<table border="1" class="fixed">
    <col width="150" />
    <col width="150" />
    <col width="150" />
    <col width="150" />
    <thead>
        <tr>
            <th>Name</th>
            <th>Address</th>
            <th>Position Applied</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody data-bind="foreach: candidates">
        <tr>
            <td data-bind="text: name"></td>
            <td data-bind="text: address"></td>
            <td data-bind="text: positionApplied"></td>
            <td align="center"><a href="#" data-bind="click: $parent.viewCandidate">View candidate</a>
            <a href="#" data-bind="click: $parent.removeCandidate">Remove candidate</a>
            </td>
        </tr>
    </tbody>
</table>

和它的JavaScript:

define(['durandal/app', 'knockout', 'canView'] , function (app, ko, cv) {


        viewCandidate: function () {

            cv.CandidateContainer(this.name, this.address, this.positionApplied);
            console.log(cv.container.name);
            document.location="#CandidateView";
        }, 

        removeCandidate: function() {
            CATObject.candidates.remove(this);
        },



    });

    return CATObject;

});

现在是我试图检索它的第二页:

<p><strong>Name: &nbsp</strong><span data-bind="text: container.name"></span></p>
<p><strong>Address: &nbsp</strong><span data-bind="text: container.address"></span></p> 
<p><strong>Position applied: &nbsp</strong><span data-bind="text:container.positionApplied"></span></p>

和它的JavaScript:

define(['durandal/app', 'knockout'] , function (app, ko) {


    var viewCandObject = {
        displayName: 'Candidate view',

        container: {},

        CandidateContainer: function(name, address, positionApplied) {
            viewCandObject.container.name=name;
            viewCandObject.container.address=address;
            viewCandObject.container.positionApplied=positionApplied
            console.log("CandidateContainer ran");

            viewCandObject.testContainer();

        },

    }
    return viewCandObject;

});

任何帮助或提示都将受到赞赏。

0 个答案:

没有答案