2017-02-16 9 views
1

したがって、2つのビューの間にマスター/詳細シナリオがあります。マスターページにはリストが表示され、アイテムの1つをクリックすると、AureliaのEventAggregatorを介してメッセージのペイロードとしてデシリアライズされたdto(マスターの選択されたアイテムから来る)を持つメッセージが子ビューに送信されます。Javascript ServiceStackクライアントのシリアル化エラー

しかし、このアイテムを子供の後続リクエストのパラメータとして渡すと(追加情報を得るために)、ペイロードオブジェクトのシリアル化が失敗します。

Master.ts:

import { JsonServiceClient } from "servicestack-client"; 
import { 
    ListPendingHoldingsFiles, 
    ListPendingHoldingsFilesResponse, 
    SendHoldings, 
    PositionFileInfo 
} from "../holdingsManager.dtos"; 
import { inject, singleton } from "aurelia-framework"; 
import { Router } from "aurelia-router"; 
import { EventAggregator } from "aurelia-event-aggregator"; 
import { GetPendingPositionMessage } from "../common/GetPendingPositionMessage"; 

@singleton() 
@inject(Router, EventAggregator) 
export class Pending { 
    router: Router; 
    positions: PositionFileInfo[]; 
    client: JsonServiceClient; 
    eventAgg: EventAggregator; 

    constructor(router, eventAggregator) { 
     this.router = router; 
     this.eventAgg = eventAggregator; 
     this.client = new JsonServiceClient('/'); 
     var req = new ListPendingHoldingsFiles(); 
     this.client.get(req).then((getHoldingsResponse) => { 
      this.positions = getHoldingsResponse.PositionFiles; 
     }).catch(e => { 
      console.log(e); // "oh, no!" 
     }); 
    } 

    openHoldings(positionInfo) { 
     this.eventAgg.publish(new GetPendingPositionMessage(positionInfo)); 
     this.router.navigate('#/holdings'); 
    } 
} 

Child.ts:

import { JsonServiceClient } from "servicestack-client"; 
import { inject, singleton } from "aurelia-framework"; 
import { Router } from 'aurelia-router'; 
import { EventAggregator } from "aurelia-event-aggregator"; 
import { GetPendingPositionMessage } from "../common/GetPendingPositionMessage"; 
import { 
    GetPendingHoldingsFile, 
    GetPendingHoldingsFileResponse, 
    Position, 
    PositionFileInfo 
} from "../holdingsManager.dtos"; 

@singleton() 
@inject(Router, EventAggregator) 
export class Holdings { 
    router: Router; 
    pendingPositionFileInfo: PositionFileInfo; 
    position: Position; 
    client: JsonServiceClient; 
    eventAgg: EventAggregator; 

    constructor(router, eventAggregator) { 
     this.router = router; 
     this.eventAgg = eventAggregator; 
     this.eventAgg.subscribe(GetPendingPositionMessage, 
      message => { 
       this.pendingPositionFileInfo = message.fileInfo; 
      }); 
    } 

    activate(params, routeData) { 
     this.client = new JsonServiceClient('/'); 
     var req = new GetPendingHoldingsFile(); 
     req.PositionToRetrieve = this.pendingPositionFileInfo; 
     this.client.get(req).then((getHoldingsResponse) => { 
      this.position = getHoldingsResponse.PendingPosition; 
     }).catch(e => { 
      console.log(e); // "oh, no!" 
     }); 
    } 
} 

子供が起動し、要求 'GetPendingHoldingsFile' を送信しようとしたときにエラーが発生します。

Failed to load resource: the server responded with a status of 500 (NullReferenceException) 

私は子供でthis.pendingPositionFileInfoは(それがnullである)、nullまたは空でないと、サーバー側では、オブジェクトが受信されていないことことを確認しました。私はAureliaには新しく、Javascriptにはあまり経験がありませんので、何か不足しているはずです。アドバイスをいただければ幸いです。

編集1

これは私がServiceStackとの相互作用てるかと間違って何かのようです。私は[email protected]^0.0.17でserviceStackのバージョン4.5.6を使用しています。私は新しいバージョンのdto(PositionFileInfo)を新しく作成し、親ビューのすべての値をコピーして、私が気付いていないjavascript型変換の奇妙さがないことを確認しましたが、ウェブサービスは依然としてヌル要求を受け取る。

+0

ここでイベントアグリゲータを使用しないでください...ルータがあまりにも複雑で冗長です。現在のレコード 'this.positionInfo = positionInfo;'を保存しておき、あなたの子にルーティングして、あなたの子が親をインポート/注入して現在のレコードを取得させるようにしてください。 – LStarky

+0

いくつかの似たようなケースのデモがあります:http://stackoverflow.com/questions/42260833/aurelia-how-can-i-modify-sidebar-content-from-inside-a-router-view – LStarky

+0

チップのおかげで、残念ながら、これはシリアル化の問題を解決しません。 – Bitfiddler

答えて

1

'client.get(...)'から 'client.post(...)'に切り替えると問題が解決しました。どうやらURLでオブジェクトを直列化しようとしたのは良い計画ではありませんでした。

+0

間違いなく良い計画です!私はあなたのコードで気づいていなかったが、まさに正しい。 – LStarky

関連する問題