【发布时间】:2014-12-06 21:47:56
【问题描述】:
无法从 javascript 中的对象获取属性,但我可以在记录其父对象时将其打印到控制台。它确实看起来像一个普通的物体。为什么我无法访问_id?
下面的代码在一个函数中:$scope.create = function() { 在我的角度视图中提交表单时被调用:<form class="form-horizontal" data-ng-submit="create()" novalidate>
那么问题来了,在我的函数中创建:
console.log($scope.account);
var tmp=$scope.account;
console.log('id:' +tmp._id);
给我:
{"user":{"displayName":"David Karlsson","_id":"548217e5402b8b8c194d9c11"},"_id":"5483235cc0d8580000152f0b","__v":0,"created":"2014-12-06T15:40:12.682Z","amount":0,"interests":[{"rate":123,"date":"2014-12-30T23:00:00.000Z","_id":"5483235cc0d8580000152f0c"}],"desc":"","name":"Acount"}
id:undefined
更改 post 方法没有帮助:
$scope.create = function() {
// Create new Income object
var copy = Object.assign({}, this.account);
console.log(copy);
}
给予:
TypeError: undefined is not a function 在 Scope.$scope.create (localhost:3000/modules/incomes/controllers/incomes.client.controller.js:12:29) 在 localhost:3000/lib/angular/angular.js:10880:21 在回调(ocalhost:3000/lib/angular/angular.js:19237:17) 在 Scope.$eval (localhost:3000/lib/angular/angular.js:12788:28) 在 Scope.$apply (localhost:3000/lib/angular/angular.js:12886:23) 在 HTMLFormElement。 (本地主机:3000/lib/angular/angular.js:19242:23) 在 localhost:3000/lib/angular/angular.js:2853:10 在 forEach (localhost:3000/lib/angular/angular.js:325:18) 在 HTMLFormElement.eventHandler (localhost:3000/lib/angular/angular.js:2852:5)
【问题讨论】:
标签: javascript