javascript - Cannot push newly created item in MongoDB to AngularJS array -
i stuck 2 full days on issues. use ruby on rails, mongodb , angularjs. when add new record database, record added in collection (table), cannot record automatically displayed current list of items.
i doing way:
$scope.posts.push(angular.extend(p, response.id)); $scope.posts.push(angular.extend(p, {id: response.id})); //tried $scope.posts.push(angular.extend(p, {_id: response.id.$oid})); //tried $scope.posts.push(angular.extend(p, {id: response.id.$oid})); //tried $scope.posts.push(response.id); //tried $scope.posts.push(response); //tried
the record still not among existing ones. after refreshing page record displayed among others. (just fyi - deleting record , splice
works well).
after investigating, might caused structure of mongodb collection/documents?
i've noticed when load data mongodb database, hash looks this:
resource {_id: object, body: null, created_at: "2015-10-26t19:14:13.016z", starred: null, title: "u8u88u8u", updated_at: "2015-10-26t19:14:13.016z", __proto__: ...}
notice first item (underscore) - _id
.
resource {id: object, title: "bla bla bla", body: null, starred: null, created_at: "2015-10-27t15:40:04.462z"…}
notice first item - id
.
may problem trying push array item contains id
instead of id
, structure of hash not identical?
i cannot make work 2 days, might non-sense typing here, trying put down on paper possible issues of why newly created record not automatically push existing array of items.
thank in advance.
Comments
Post a Comment