【发布时间】:2016-02-07 11:38:37
【问题描述】:
这里是后端函数
userDetail : function(req,res){
User.findOne().where({id : req.userID}).exec(
function findOneCB(err, result) {
if (err) {
sails.log.error("Error Occurred : "+ err);
}
if(result != undefined ){
Account.find().where({userID: req.userID},{StatusCode :"Successful"}).exec(
function findCB(err, accounts) {
if (err) {
sails.log.error("Error Occurred : "+ err);
}
if(accounts != undefined ){
var sendData={
userData:result,
accountData :accounts
};
console.log(sendData);
res.json(sendData);
}
});
}
});
}
这里是前端资源函数
(function (){
"use strict";
angular.module('userAccounts').factory('userAccountsResource',[
"$resource","$http",userAccountsResource]);
function userAccountsResource($resource,$http){
return {
getApprovedAccounts:function(){
return $resource('api/account/approvedBankAccounts');
},
getUserDetail : function(){
return $http.get('api/user/userDetail');
}
}
}
})();
控制器上的资源函数调用
vm.userDetail= userAccountsResource.getUserDetail();
后端发送响应数据为
{ userData:
{ email: 'thusitha@gmail.com',
userName: 'thusithz',
userRole: 'Standard',
selectedAccountList:
[ { accountName: 'HSBC name',
CFIXID: 'HSBC_CFIXID',
id: '563c4d7e802127d51b3d80c7',
StatusCode: 'Pending' },
{ accountName: 'NSB plus',
CFIXID: 'NSB_CFIXID',
id: '563c4de1802127d51b3d80c8',
StatusCode: 'Pending' } ],
createdAt: '2015-11-06T05:10:18.690Z',
updatedAt: '2015-11-06T05:52:24.820Z',
verifyCode: '1446786618698FfL2_gHGexhOb_JQ',
pincode: '1111',
id: '563c363aa45b2d841afc63ab' },
accountData:
[ { TimeStamp: '1446797352',
TransactionID: 'LGPS201511613253518097',
SecretTransactionKey: 'HSBC_CFIXID03636867',
ReplyID: '35753',
StatusCode: 'Successful',
StatusDescription: 'Authentication Failed',
Tags: '',
ReturnURL: '',
userID: '563c363aa45b2d841afc63ab',
accountName: 'HSBC plus',
CFIXID: 'HSBC_CFIXID',
VerificationCode: 'LGPS3309914431991402',
createdAt: '2015-11-06T07:55:35.229Z',
updatedAt: '2015-11-06T07:55:35.229Z',
id: '563c5cf7463ef3eb0aeaf57a' } ] }
它显示了 {{}}
这是为什么..?函数正确链接到后端函数并返回正确的响应,但为什么它显示为 {{}}
【问题讨论】:
标签: angularjs node.js sails.js mongodb-query