array nodes
Closed this issue · 2 comments
nadimtuhin commented
how do we do something like
<occupants>
<user affiliation='member'>user1@shakespeare.lit</user>
<user affiliation='member'>user2@shakespeare.lit</user>
</occupants>
from
occupants = [{
affiliation: 'member',
jid: 'user1@shakespeare.lit'
}, {
affiliation: 'member',
jid: 'user2@shakespeare.lit'
}]
nadimtuhin commented
fixed
const User = jxt.define({
name: 'occupants',
element: 'user',
fields: {
affiliation: helpers.attribute('affiliation'),
jid: helpers.text()
}
});
const MucLight = jxt.define({
name: 'info',
element: 'query',
fields: {
occupants: helpers.subMultiExtension('', 'occupants', User)
}
});
jlibrun22 commented
An extension to this question what if I also what to add element within a node with multiple of the same type.
For example, I want to do something like
<occupants>
<user affiliation='member'>user1@shakespeare.lit</user>
<user affiliation='member'>user2@shakespeare.lit</user>
<someValue = 'foo'/>
<anotherOne= 'bar'/>
</occupants>
and use it like this
occupants = {
user:[object1,object2],
someValue:'foo',
anotherOne:'bar'
}