x-tag / core

The Heart of X-Tag
http://x-tag.github.io/
Other
1.25k stars 151 forks source link

[Question] Getting attribute from HTML string parser #146

Closed bigopon closed 8 years ago

bigopon commented 8 years ago

Hi,

Does xtag currently support auto get attribute from HTML string?

says if I have this

document.body.innerHTML += '<hello-world text="hola" />'

how do i get text attribute automatically in xtag instead of

lifecycle: {
    created: function() { var text = this.getAttribute('text') }
}
csuwildcat commented 8 years ago

Yep, read the Accessors section of the guide on the site On Mar 30, 2016 4:27 PM, "bigopon" notifications@github.com wrote:

Hi,

Does xtag currently support auto get attribute from HTML string?

says if I have this

document.body.innerHTML += ''

how do i get text attribute automatically in xtag instead of

lifecycle: { created: function() { var text = this.getAttribute('text') } }

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/x-tag/core/issues/146

bigopon commented 8 years ago

Oh sorry I just realized that was a wrong question.

What i meant was if I have this:

accessors: {
    text: {
        set: function (val) { this.textContent = val }
    }
}

can we have it to work when we do:

document.body.innerHTML += '<hello-world text="hola"/>'

will result in

<hello-world text="hola">hola</hello-world>

without doing this:

created() { this.textContent = this.getAttribute('text') }
csuwildcat commented 8 years ago

Yes, if you add the attribute linkage to your 'text' accessor object:

accessors: { text: { attribute: {}, set: function (val) { this.textContent = val } } } On Mar 30, 2016 6:05 PM, "bigopon" notifications@github.com wrote:

Oh sorry I just realized that was an unclear question.

What i meant was if I have this:

accessors: { text: { set: function (val) { this.textContent = val } } }

can we have it to work when we do:

document.body.innerHTML += ''

will result in

hola

without doing this:

created() { this.textContent = this.getAttribute('text') }

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/x-tag/core/issues/146#issuecomment-203701024

bigopon commented 8 years ago

oh, sorry i'll read the doc more carefully.

thanks.