Fórumok

How to put the attribute "data-userId"

l ll, módosítva 9 év-val korábban

How to put the attribute "data-userId"

Regular Member Bejegyzések: 158 Csatlakozás dátuma: 2011.12.12. Legújabb bejegyzések
Hi!

var el = A.Node.create('<div></div>');
el.set('id',userId);
el.set('data-userId',userId);
el.setData('data-userId',userId);


3 and 4 lines not work
thumbnail
Kyle Joseph Stiemann, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

Liferay Master Bejegyzések: 760 Csatlakozás dátuma: 2013.01.14. Legújabb bejegyzések
Hi,
Try using element.setAttribute() instead of Node.set():

el.setAttribute('data-userId',userId);

- Kyle
l ll, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

Regular Member Bejegyzések: 158 Csatlakozás dátuma: 2011.12.12. Legújabb bejegyzések
I can not mix aui and pure js.
A.Node.create('<div data-userid="</code></pre><br /><img alt=" emoticon" src="@theme_images_path@/emoticons/smile.gif"></div>
thumbnail
Evan Thibodeau, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

New Member Bejegyzések: 14 Csatlakozás dátuma: 2012.03.29. Legújabb bejegyzések
Instead of using ".set" try using ".attr" like this:

el.attr('data-userId', userId);
thumbnail
Kyle Joseph Stiemann, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

Liferay Master Bejegyzések: 760 Csatlakozás dátuma: 2013.01.14. Legújabb bejegyzések
l ll:
I can not mix aui and pure js.
A.Node.create('<div data-userid="</code></pre><br /><img alt=" emoticon" src="@theme_images_path@/emoticons/smile.gif"></div>
<br>Why not?<br><br><a href="http://jsfiddle.net/qypt9tcx/1/">This code works perfectly for me by the way:</a><br><br><span style="font-family: Courier New">var el = A.Node.create('&lt;div&gt;&lt;/div&gt;');<br>el.set('id',userId);<br>el.setAttribute('data-userId',userId);</span><br><br>- Kyle
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Wait, isn't the setData() and getData() methods supposed to be preferred over direct attribute access? The whole point was to treat the attribs as keyed data and using the data methods enforces this pattern.

So in that case the OP should use el.getData("userId") and el.setData("userId", userId).
l ll, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

Regular Member Bejegyzések: 158 Csatlakozás dátuma: 2011.12.12. Legújabb bejegyzések
Kyle Joseph Stiemann

Excuse me. It appeared that I use AUI 1.5 and there is no setAttribute there. At the same time you showed an instance of AUI 2.0. That is why we did not understand each other.
thumbnail
Kyle Joseph Stiemann, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

Liferay Master Bejegyzések: 760 Csatlakozás dátuma: 2013.01.14. Legújabb bejegyzések
When I test the code with AlloyUI 1.5 it also works. Perhaps there's a js error in your code.

@David,
The docs for AlloyUI 1.5 recommend Node.setAttribute() for custom attrs, and specify that Node.setData() will not affect the DOM node. I don't know if that changed in other versions though.

- Kyle
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: How to put the attribute "data-userId"

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
@Kyle: Nuts

emoticon

Actually I had gotten there from a different path, was working through the source for the aui:nav-item tag where the getData() is used vs getAttribute() and online stuff saying it's preferred because it clearly signifies intents...

Ah, well, thanks for following up.
l ll, módosítva 8 év-val korábban

RE: How to put the attribute "data-userId" (Válasz)

Regular Member Bejegyzések: 158 Csatlakozás dátuma: 2011.12.12. Legújabb bejegyzések
Thanks for the answer.

Will be correct:


getData('userId');
and
setData('userId',1111);