初始加载时的列表视图。

添加新省后的列表视图。

添加省后的HTML结构视图。

所以,我的问题是,为什么所有的孩子都有相同的结构、大小和CSS样式,但他们看起来不同?jQuery
. 添加后,这些新条目将添加到数据库中,然后将其保留以供将来搜索。
现在,每个条目都由span
并且每个被添加的国家或州都使用与其他兄弟国家相同的结构。问题是,当创建时查询
尽管每个元素都有相同的分支,但这些新的子元素的可视化效果不同。
您可以在下面找到一个工作示例test platform.
我使用thymeleaf作为元素的初始负载,这是使用的代码。
<div class="country-container">
<th:block th:each="country : ${countries}">
<div class="country-row">
<span class="father">
<i class="fa fa-eye child-toggle"></i>
<textarea class="data" maxlength="50" rows="1" cols="25" th:text="${country.countryPk}"></textarea>
<p>Cód: </p>
<textarea class="country-code" maxlength="4" rows="1" cols="4" th:text="${country.countryCode}"></textarea>
<i class="fa fa-plus-circle add-province"></i>
<i class="fa fa-minus-circle delete-country"></i>
</span>
<div class="child-container">
<th:block th:each="province : ${country.provinceSet}">
<span class="child">
<i class="fa fa-minus-circle delete-province"></i>
<textarea class="data" rows="1" cols="25" th:text="${province.provinceId.provincePk}"></textarea>
<p>Núm: </p>
<textarea class="province-number"
maxlength="2"
rows="1"
cols="4"
th:text="${province.provinceNumber}">
</textarea>
<i class="fas fa-arrow-circle-right info-province"></i>
</span>
</th:block>
</div>
</div>
</th:block>
</div>
这是我在JQuery
创建新的省或州。
// Add a new province container to a country row
$(document).on('click', '.add-province', function() {
// Span where the province's father country name is located
var father = $(this).closest('.father');
// Father country's row
var countryRow = $(father).closest('.country-row');
// Provinces' container
var childContainer = $(father).next('div.child-container');
var actionContainer = $('<div class="action-holder full-width add-span">');
var addProvinceButton = $('<button type="button" class="add-province-button extra-small green">Agregar</button>');
// If there is no child container (div where all the provinces are) we need to add one to the country row
if(childContainer.length === 0) {
childContainer = $('<div class="child-container">');
$(countryRow).append(childContainer);
}
// Set up the span where the province will be located at
var newChild = $('<span class="child">');
var minusIcon = $('<i class="fa fa-minus-circle delete-province"></i>');
var textArea = $('<textarea class="data" rows="1" cols="25"></textarea>');
var textProvinceNumber = $('<textarea class="province-number" maxlength="2" rows="1" cols="4"></textarea>' +
'</textarea>');
// Append the elements to our child
newChild.append(minusIcon);
newChild.append(textArea);
newChild.append($('<p>Num: </p>'));
newChild.append(textProvinceNumber);
// Append the new child to his father
childContainer.append(newChild);
actionContainer.append(addProvinceButton);
actionContainer.append($('<p class="cancel-text">Cancelar</p>'));
newChild.append(actionContainer);
// Focus on the text box of the new province row
textArea.focus();
});
初始加载时的列表视图。

添加新省后的列表视图。

添加省后的HTML结构视图。

所以,我的问题是,为什么所有的孩子都有相同的结构、大小和CSS样式,但他们看起来不同?