截图:(https://i.stack.imgur.com/w8z5M.png)
我的代码:(ejs文件代码)
<div class="container">
<h1 class="text-center">Domain Age Checker</h1>``
<form action="/domainagechecker" method="post">
<div class="form-group">
<label for="domain">Domain URL:</label>
<textarea
class="form-control"
type="text"
name="domain"
id=""
placeholder="write a domain"
></textarea>
</div>
<br />
<div class="form-group">
<button class="btn btn-block btn-primary">Get Details</button>
</div>
</form>
<br />
<%if (flag) { %>
<table class="table table-striped">
<thead>
<tr>
<th>Domain Name</th>
<th>Running Server</th>
<th>Creation Date</th>
<th>Domain Age</th>
<th>Last Renewal</th>
<th>Expiry Date</th>
</tr>
</thead>
<tbody>
<tr>
<td><%=data.domainName%></td>
<td><%=data.registrar%></td>
<td><%=date%></td>
<td><%=domainAge%></td>
<td><%=data.updatedDate%></td>
<td><%=data.registryExpiryDate%></td>
</tr>
</tbody>
</table>
<% } %>
</div>
字符串
- (node js apis:)
app.set('view engine', 'ejs');
app.get("/", (req,res) => {
res.render("domainagechecker", {
title: "Domain Details",
data: "",
flag: false,
date: "",
domainAge: "",
});
})
app.post("/domainagechecker", async (req, res) => {
var domain = req.body.domain;
console.log(domain);
var list_Domains = domain.split(" ");
for (let i = 0; i < list_Domains.length; i++) {
console.log("sl.no " + i + " " + list_Domains[i]);
if (isValidDomain(list_Domains[i])) {
var result = await whoisinfo(list_Domains[i]);
console.log(result);
var date = moment(result.creationDate).format("YYYY-MM-DD");
var curDate = moment(new Date()).format("YYYY-MM-DD");
console.log("creation date: " + date);
console.log(curDate);
var a = moment(date);
var b = moment(curDate);
console.log(a);
console.log(b);
var years = b.diff(a, "years");
a.add(years, "years");
var months = b.diff(a, "months");
a.add(months, "months");
var days = b.diff(a, "days");
var domainAge =
years + " years " + months + " months and " + days + " days";
res.render("domainagechecker", {
title: "Domain Details",
data: result,
flag: true,
date: date,
domainAge: domainAge,
domain1: domain,
});
} else {
res.send("please enter domain name as 'example.com' (only domain name)");
}
}
});
型
我已经尝试了for循环,但它对我不起作用。请告诉我解决方案。
API正在根据输入获取结果,但ejs模板仅显示第一个值。
1条答案
按热度按时间1yjd4xko1#
你是一个接一个地渲染,一次得到结果,而不是把所有的数据放在数组中,那么你将得到所有的数据
字符串
然后推送所有数据:
型
你的最终ejs应该在results Array中呈现完整的数据:
型
nodejs:
型