Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > pl.comp.lang.javascript > #3581

JA a tworzenie elementów DOM

Path csiph.com!news.mixmin.net!news.unit0.net!news.nask.pl!news.nask.org.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From Roman Tyczka <noemail@because.no>
Newsgroups pl.comp.lang.javascript
Subject JA a tworzenie elementów DOM
Date Tue, 29 Jan 2019 14:53:56 +0100
Organization ATMAN - ATM S.A.
Lines 45
Sender romek@tyczka.no.found
Message-ID <11pc55hmknr5j.dlg@tyczka.com> (permalink)
NNTP-Posting-Host ip-94-75-90-137.wave.com.pl
Mime-Version 1.0
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding 8bit
X-Trace node2.news.atman.pl 1548770036 22080 94.75.90.137 (29 Jan 2019 13:53:56 GMT)
X-Complaints-To usenet@atman.pl
NNTP-Posting-Date Tue, 29 Jan 2019 13:53:56 +0000 (UTC)
User-Agent 40tude_Dialog/2.0.15.84
Xref csiph.com pl.comp.lang.javascript:3581

Show key headers only | View raw


Wyczytałem, że tworzenie struktury dokumentu przez takie "html stringi"
jest złe:

data.forEach(function(entry) {
	$('#filelist').append(
        `<li class="list-group-item">
           <strong class="bundle-info">plik: 
            <a href="${entry.URL}">${entry.OriginalName}</a>
           </strong> - <strong class="bundle-info">
           ${entry.Desc}</strong>
         </li>`
	}

I że powinno się obiektowo i w ogóle, zrobiłem tak:

data.forEach(function(entry) {
	let li = document.createElement('li');
	li.className = 'list-group-item';
	let strong = document.createElement('strong');
	strong.className = 'bundle-info';
	strong.appendChild(document.createTextNode('plik: '));
	let a = document.createElement('a');
	a.href = `${entry.URL}`;
	a.appendChild(document.createTextNode(`${entry.OriginalName}`));
	strong.appendChild(a);
	li.appendChild(strong);
	li.appendChild(document.createTextNode(' - '));
	strong = document.createElement('strong');
	strong.className = 'bundle-info';
	strong.appendChild(document.createTextNode(`${entry.Desc}`));
	li.appendChild(strong);
	frag.appendChild(li);
});

I teraz się zastanawiam... po pierwsze zajęło mi to w pip więcej czasu, po
drugie jest to mniej jednak czytelne, bo za cholerę z tego kodu nie widzę
struktury, po trzecie jakiekolwiek zmiany będą wymagały rozkminy co w czym
i pod czym siedzi... czy naprawdę tak się robi czy coś źle mi się
zrozumiało? A jeśli tak się robi to może jest jakaś zgrabniejsza forma
zapisu niż tona zmiennych?

-- 
pozdrawiam
Roman Tyczka

Back to pl.comp.lang.javascript | Previous | NextNext in thread | Find similar


Thread

JA a tworzenie elementów DOM Roman Tyczka <noemail@because.no> - 2019-01-29 14:53 +0100
  Re: JA a tworzenie elementów DOM Roman Tyczka <noemail@because.no> - 2019-01-29 14:54 +0100
  Re: JA a tworzenie elementów DOM Borys Pogoreło <borys@pl.edu.leszno> - 2019-01-29 15:40 +0100

csiph-web