Below is my Modal controller. Se_chnl and Se_segn_rqst are the Loopback models. I'm initializing the modal form in the first step. The $scope.Se_chnl_find() is getting me a list from the backend which I load as a dropdown menu in the modal. This call to loopback works fine.
Then later on once the form is filled, I call the submit function and in that I call the create function of loopback Se_segn_rqst.create($scope.rqst) $scope.rqst contains the parameters for creating that rqst.
Now, once I have created this "rqst", I want to retrieve ID of the latest created request by that user and store it in the global variable. But the loopback api/MySQL doesn't return anything. Record is created in the backend when create is used. But the find function doesn't work.
I tried the find filter in Strongloop/Loopback explorer and it works there. Not sure why it is not returning anything when I tried it from the controller.
codeApp.controller('ModalInstanceCtrl', function($scope, $modalInstance, $state, Se_chnl, Se_segn_rqst) {
var defaultForm = {
cmpgn_nm: "",
cmpgn_id: "",
strgy_id: "",
rqst_typ_cd: "",
chnl_id: ""
}
$scope.channels = Se_chnl.find({
filter: {
"fields": {
"chnl_nm": true,
"chnl_id": true
}
}
});
$scope.rqst = angular.copy(defaultForm);
$scope.rqst.rqst_id = 0;
$scope.submit = function(reqForm) {
$scope.rqst.rqst_nm = $scope.rqst.cmpgn_nm;
$scope.rqst.rqst_stat_cd = 'DRAFT';
$scope.rqst.insrt_user_id = $scope.$parent.user_id;
$scope.rqst.insrt_dt = new Date();
Se_segn_rqst.create($scope.rqst);
$scope.$parent.requested_id = Se_segn_rqst.find({
filter: {
"fields": {
"rqst_id": true
},
"order": "insrt_dt DESC",
"limit": 1,
"where": {
"rqst_stat_cd": "DRAFT",
"insrt_user_id": "xyz123"
}
}
});
$modalInstance.dismiss('cancel');
};
$scope.resetForm = function(reqForm) {
$scope.rqst = angular.copy(defaultForm);
reqForm.$setPristine();
reqForm.$setUntouched();
};
});
This is the piece returning no value. I want an id in the requested_id global variable. The filter is performing correctly in the Strongloop explorer, so there is no syntax error.
$scope.$parent.requested_id = Se_segn_rqst.find({
filter: {
"fields": {
"rqst_id": true
},
"order": "insrt_dt DESC",
"limit": 1,
"where": {
"rqst_stat_cd": "DRAFT",
"insrt_user_id": "xyz123"
}
}
});
需要更多信息,但我们可以在此处讨论其余信息: https : //groups.google.com/forum/#!topic/loopbackjs/qdPaorTpOAA
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.