2017-12-14 18 views
0

Save Dataからコードをコピーしました。このようなものですTransactionResult.Successは自分のmutableData(Firebase)を更新しません

void addScoreToLeaders(string name, int score ,string 
    key,Dictionary<string,object> childUpdates){  
    reference.Child ("leaders").KeepSynced (true); 
    reference.Child ("leaders").RunTransaction(mutableData =>{ 
     List<Dictionary<string,object>> leaders = mutableData.Value as 
          List<Dictionary<string,object>>; 
      if(leaders == null){ 
       leaders = new List<Dictionary<string,object>>(); 
      } else if(mutableData.ChildrenCount >= MAX_SCORE){ 
       int minScore = int.MaxValue; 
       Dictionary<string,object> minValue = null; 
       foreach(var child in leaders){ 
        if(!(child is Dictionary<string,object>)) continue; 
        int childScore = (int)((Dictionary<string,object>)child) 
         ["score"]; 
        if(childScore < minScore){ 
         minScore = childScore; 
         minValue = child; 
        } 
       } 
       if(minScore > score){ 
        return TransactionResult.Abort(); 
       } 

       leaders.Remove (minValue);    
      } 

      //Add the new high score 
      Dictionary<string ,object> newScoreMap = new 
      Dictionary<string,object>(); 
      LeaderBoardEntry entry = new LeaderBoardEntry (name, score); 
      newScoreMap = entry.ToDictionary(); 
      leaders.Add (newScoreMap); 
      mutableData.Value = leaders; 
      return TransactionResult.Success (mutableData); 
     }); 
    } 

いいが、二つのことがあります正しく起こりません:

  • TransactionResult.Success(mutableDataは)場所

  • に新しいデータを保存しません
  • 私はメソッドを呼び出すたびにmutableDataを返します。

答えて

0

[解決済み]コードを検証し、いくつかのテストを試した結果、解決策が見つかりました。 mutableData.Valueネイティブこのインスタンスに含まれるデータを返さため

Dictionary<string,object> leaders = mutableData.Value as 
         Dictionary<string,object>; 

List<Dictionary<string,object>> leaders = mutableData.Value as 
         List<Dictionary<string,object>>; 

に置き換える:あるコード引き起こす問題の

行番号5(5)タイプ、私はのようなデータを保存しました。辞書<。文字列、オブジェクト>;

関連する問題