简体   繁体   English

如何使用回送API和angularjs检索最新创建的记录

[英]How to retrieve the latest created record using loopback api and angularjs

Below is my Modal controller. 以下是我的模态控制器。 Se_chnl and Se_segn_rqst are the Loopback models. Se_chnl和Se_segn_rqst是回送模型。 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. $ scope.Se_chnl_find()从后端获取了一个列表,该列表作为模式中的下拉菜单加载。 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. 然后稍后在填写表单后,我会调用Submit函数,并在其中调用回送的create函数Se_segn_rqst.create($ scope.rqst)$ scope.rqst包含用于创建该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. 现在,一旦创建了该“ rqst”,我想检索该用户最新创建的请求的ID并将其存储在全局变量中。 But the loopback api/MySQL doesn't return anything. 但是环回api / MySQL不会返回任何内容。 Record is created in the backend when create is used. 使用create时,将在后端创建记录。 But the find function doesn't work. 但是find函数不起作用。

I tried the find filter in Strongloop/Loopback explorer and it works there. 我在Strongloop / Loopback资源管理器中尝试了查找过滤器,并且该过滤器在此起作用。 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. 我想要一个ID全局变量Requested_id。 The filter is performing correctly in the Strongloop explorer, so there is no syntax error. 筛选器在Strongloop资源管理器中正常运行,因此没有语法错误。

$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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 JavaScript 从 Azure 表存储中检索最新记录? - How to retrieve latest record from Azure table storage using JavaScript? JavaScript:如何从IndexedDB检索最新记录? - JavaScript: How to retrieve the latest record from IndexedDB? 如何使用参与 API 从 hubspot 检索最新参与 - How to retrieve the latest engagements from hubspot using Engagements API 使用 LoopBack API Explorer - Using the LoopBack API Explorer 如何使用javascript(和Graph API)仅检索和输出帖子中最新的Facebook评论? - How do I retrieve and output only the latest Facebook comment on my post using javascript (and Graph API?) 如何在Angularjs中使用相同的Web API Get请求检索和追加数据 - How to retrieve and append data using the same web api get request in Angularjs 如何使用AngularJS从Json检索数据? - How to retrieve data from Json using AngularJS? 如何使用 AngularJs 从文本框中检索值? - How to retrieve the value from textbox using AngularJs? 使用Web API从数据库中检索图像,然后在angularJS中显示它 - Retrieve image from database using Web API, then displaying it in angularJS 如何运行使用yeoman创建的AngularJS应用程序 - How to run AngularJS app created using yeoman
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM