我有这样的数据结构: -
#!/usr/bin/env bash
echo "cleaning from previous run...."
ps -W | awk '/node.exe/,NF=1' | xargs kill -f
echo "done cleaning"
yarn start
基本上,我正在努力收集一个人工作的所有过去的工作以及他在那里完成的工作。所以这是一个列表结构列表。我想知道如何在UI中为Thymeleaf / Spring mvc处理这个问题。
我正在尝试创建UI,如图所示。有一个表格可以输入数据。要输入workDoneSentence,我想打开另一个模态。并且句子列表应该绑定到正确的工作索引。
工作完成打开模式以输入完成工作句子的列表。
我对此的html代码如下: -
WorkHistory{
List<Jobs> jobs;
}
Jobs{
List<String> workDoneSentences;
}
我不确定如何链接workDone输入。请建议。 谢谢!
答案 0 :(得分:5)
<td><a class="btn btn-primary btn-md" id="work_done0" name="work_done0" th:href="Modal">Work done</a></td>
应根据您自己的需求配置模态部分
答案 1 :(得分:2)
我尝试了如下,它运作正常。
模板:为每个作业创建唯一的“模态”。 (工作list.html)
<form method="post" action="#" th:action="@{/work-list}" th:object="${workHistoryDetails}">
<table>
<thead>
<tr>
<th>
<button type="submit" name="addRow" th:text="'Add Row'">Add row</button>
</th>
</tr>
</thead>
<tbody>
<tr id='addr_work0' th:each="workRow, rowStat : *{jobs}">
<td th:text="${rowStat.index + 1}"></td>
<td><input type="text"
placeholder='Company Name' class="form-control" th:field="*{jobs[__${rowStat.index}__].companyName}"/></td>
<td><input type="text"
placeholder='Company city' class="form-control" th:field="*{jobs[__${rowStat.index}__].city}"/></td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" th:attr="data-target='#myModal'+${rowStat.index}" >Open modal</button></td>
<!-- The Modal -->
<div class="modal fade" th:id="'myModal'+${rowStat.index}">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<input type="text"
placeholder='Company Name' class="form-control" th:field="*{jobs[__${rowStat.index}__].workDoneSentences[0]}"/>
<input type="text"
placeholder='Company city' class="form-control" th:field="*{jobs[__${rowStat.index}__].workDoneSentences[1]}"/>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="Add" class="btn btn-danger" />
</form>
控制器:
@ModelAttribute("workHistoryDetails")
public WorkHistory populateWorkHistories() {
return this.workHistory.getAllHistoryDetail();
}
@Autowired
WorkHistoryService workHistory;
@GetMapping("/work-list")
public String greeting(final WorkHistory workHistoryDetails) {
return "work-list";
}
@RequestMapping(value="/work-list",method=RequestMethod.POST)
public String create(final WorkHistory workHistoryDetails) {
this.workHistory.setJobs(workHistoryDetails);
return "work-list";
}
// for adding new row job to jobs list
@RequestMapping(value="/work-list", params={"addRow"})
public String addRow(final WorkHistory workHistoryDetails, Model model) {
Jobs jobRow = new Jobs("","",new ArrayList<>());
workHistoryDetails.getJobs().add(jobRow);
model.addAttribute("workHistoryDetails", workHistoryDetails);
return "work-list";
}
服务:仅为了测试:
@Service
public class WorkHistoryService {
static WorkHistory workHistoryDetails =new WorkHistory();
static{
List<String> workDones = new ArrayList<>();
workDones.add("angular");
workDones.add("description");
List<String> workDones1 = new ArrayList<>();
workDones1.add("java,c++");
workDones1.add("description also");
Jobs job1 = new Jobs("Twitter", "USA",workDones);
Jobs job2 = new Jobs("Microsoft", "USA",workDones1);
List<Jobs> jobList = new ArrayList<>();
jobList.add(job1);
jobList.add(job2);
workHistoryDetails.setJobs(jobList);
}
public WorkHistory getAllHistoryDetail(){
return workHistoryDetails;
}
public void setJobs(WorkHistory workHistory){
workHistoryDetails.getJobs().clear();
List<Jobs> jobs = workHistory.getJobs();
for (Jobs job : jobs) {
workHistoryDetails.getJobs().add(job);
}
}
}
招聘网域
public class Jobs {
private String companyName;
private String city;
private List<String> workDoneSentences;
//default constructor important!
public Jobs() {
super();
}
//setter getter
}
我希望它可以帮到你。