0
안녕하세요 사용자가 추가하거나 제거 할 수있는 동적 필드를 사용자가 채 웁니다. 이 양식이 완성되면 docxtemplater를 사용하여 단어 문서가 생성됩니다. 마지막 항목을 입력하는 중이지만 배열을 만들어서 여러 항목을 반복하여 내 문서에 입력 할 수 있습니다.Docxtemplater 배열에만 마지막 값을 입력하십시오.
자바 스크립트 :
var methods = document.getElementsByName("Method[]");
var attributes = document.getElementsByName("Attribute[]");
var locations = document.getElementsByName("Location[]");
var len = methods.length;
var mdata = []
for (var x = 0; x < len; x++){
var element = {
"Method": methods[x].value,
"Attribute": attributes[x].value,
"Location": locations[x].value
};
mdata.push(element);
}
console.log(JSON.stringify(mdata));
var docxvar = {
ShelfLifeExpiry: $("#shelfdrp").val(),
monograph: "2",
"testloop":
[
mdata
]
};
docx.docxtemplater.setData(docxvar);
문서 서식 파일 : 콘솔에서
{#testloop}
{Method}
{Attribute}
{Location}
{/testloop}
: 문서에 콘솔에있는 것과
[{"Method":"3434","Attribute":"434","Location":"434"},{"Method":"4343","Attribute":"3434","Location":"232"},{"Method":"3231","Attribute":"232","Location":"323321"}]
어떻게 모든 값을받을 수 있나요 ?
감사합니다.
실제로
내가 testloop '에서 [] 제거했다 그것을 알아 냈다 –