3

こんにちは、デプロイ済みに投稿すると、コンソールにこの奇妙なエラーが表示されます

Object {name: "MongoError", message: "key $$hashKey must not start with '$'", status: 400}

コード

 dpd.timesheetsdone.post({
      "projectId": $scope.projectId ,
      "formandSig":  $scope.signature,
      "timesheets": $scope.timesheets

    }, function (result, err) {
      if (err) return console.log(err);
      console.log(result, result.id);
    });

プロジェクト ID と署名は単純な文字列、タイムシートは配列です

scope.timesheets を次のように置き換えた場合

  [
    {
        "projectId": "1000",
        "date": "2015-05-15T22:00:00.000Z",
        "start": "25200"
    }
]

できます..

onsole.log(scope.timesheet... は、同じ値 + とハッシュ キーを持つオブジェクトを返します

4

2 に答える 2

3

Angular は、配列$$hashKey内のすべてのオブジェクトに自動的に追加します。$scope.timesheetsあなたはこれらを取り除くことができますangular.toJson($scope.timesheets)

したがって、投稿は次のようになります。

 dpd.timesheetsdone.post({
  "projectId": $scope.projectId ,
  "formandSig":  $scope.signature,
  "timesheets": angular.toJson($scope.timesheets)
  ...
于 2015-05-25T14:07:08.557 に答える
2

JSON へのハッシュ キー解析タイムシートを削除 これがハッシュ キーを削除する正しい/最善の方法かどうかわからない?

      $scope.sign = function() {
   var sheets = angular.toJson($scope.timesheets);
   var sheets = JSON.parse(sheets);
    dpd.timesheetsdone.post({
      "projectId": $scope.projectId ,
      "formandSig":  $scope.signature,
      "timesheets": sheets

    }, function (result, err) {
      if (err) return console.log(err);
      console.log(result, result.id);
    });
  }
于 2015-05-25T14:37:47.060 に答える