0

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;

});

今、私がそれを取得しようとしているときの2番目のページ:

<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;

});

ヘルプやヒントをいただければ幸いです。

4

0 に答える 0