0
我正在为slackbot的字段中创建一个小码。它意味着返回与松弛中请求的日期相匹配的所有记录。现在它被设置为只返回第一个记录,但我需要所有的记录。我对此很新,我很抱歉如果这是一个基本问题,但任何帮助都会很棒。以下是我到目前为止。字段小程序 - 不返回所有匹配的记录
var _ = require('underscore');
var s = require('underscore.string');
exports.endpoint = exports.endpoint = function (request, response) {
var jobDate = request.body.text;
// Get the date from Job Notes
var date = `${(jobDate)}`;
// Find all records with the given date
var query = {date: date};
return client.list('job_notes', query).then(function (records) {
// This is only pulling the first record
我需要所有匹配日期的记录,这是我相信我需要一个for循环的地方。
var record = records[0];
if (!record) return `No data found for ${jobDate}`; // Did not match any record
var employee = record.employee[0];
var job = record.job[0];
var attributes = [
{title: 'Date', value:date, short: true},
{title: 'Time', value:record.time, short: true},
{title: 'Employees', value:employee, short: true},
{title: 'Job', value:job, short: true},
{title: 'Note', value:record.note, short: true},
];
return {
attachments: [{
fallback: record.name,
title: record.name,
fields: attributes,
}]
}
})
}
谢谢,我会试试这个,让你知道。我很欣赏快速反应! – chasewarner