首页 > 解决方案 > 在 Response Post 对象中传递从请求查询返回的数据

问题描述

我的 Angular 编码已经生锈了,因为我有一段时间没有这样做了,但是我想做的是获取从列表控制器返回的值列表,并将它们注入到我的响应帖子中到将使用此列表的搜索控制器搜索存储库。

这是我迄今为止尝试过的——

1 - 在 $scope.data{} 初始化程序中使用 Guid:[] 初始化列表数组

//Initailize 
$scope.data = {
    selection: null,
    start: '',
    end: '',
    minDate: new Date(2017, 01, 01),
    defaultStartDate: moment({ year: currentDate.getFullYear(), month: currentDate.getMonth(), day: currentDate.getDate() }),
    defaultEndDate: moment({ year: currentDate.getFullYear(), month: currentDate.getMonth(), day: currentDate.getDate() + 1 }),
    format: 'YYYY-MM-DD HH:mm:ss.SSS',
    elasticUrl: '',
    dnsHost: '',
    messageTypes: [],
    scrollId: '',
    TID: '',
    Guids: []
};

2 - 从搜索控制器返回我感兴趣的列表 $scope.Guids = data.Guids

var search = function () {
    NProgress.start();
    var ospLogsSearchParam = {
        StartDate: $scope.data.start,
        EndDate: $scope.data.end,
        ElasticUrl: $scope.data.elasticUrl,
        MessageTypes: $scope.data.messageTypes,
        DnsHost: $scope.data.dnsHost,
        TID: $scope.data.TID,
    };
    var queryString = $.param(ospLogsSearchParam);
    $http.get("/api/search?" + queryString).success(function (data) {
        $scope.isLoading = false;

        $scope.total = data.Total;
        $scope.took = "";
        $scope.tookMins = "";
        $scope.successCount = "";
        $scope.errorCount = "";
        $scope.tps = "";
        $scope.Guids = data.Guids; (data list)
    }).finally(function () {
        NProgress.done();
    });
}

3 - 将此值(Guids:$scope.data.Guids)注入 SearchParameter 对象的 Guids 字段,我将发送第二个搜索控制器。

function invokeParse() {
    var ospLogsSearchParam = {
        StartDate: $scope.data.start,
        EndDate: $scope.data.end,
        ElasticUrl: $scope.data.elasticUrl,
        MessageTypes: $scope.data.messageTypes,
        DnsHost: $scope.data.dnsHost,
        TID: $scope.data.TID,
        Guids: $scope.data.Guids (data trying to send to back end controller)
    };
    var parse = {
        Logs: $scope.filteredItems,
        DNSName: !$scope.data.dnsHost ? 'none' : $scope.data.dnsHost,
        OspLogsSearchParams: ospLogsSearchParam
}

预期结果是后端搜索控制器将使用列表中的每个值作为 where 过滤器执行搜索。

实际结果是没有使用搜索请求中的值填充 guid 列表。

标签: angularjs

解决方案


推荐阅读