I am building a webapp for editing email content, and have a problem when saving content child elements; I can modify the children via ctx in the webapp but, when I save via Storage object, removed children still remain. That is, if I load the following content:
<content>
<child id="1" ... />
<child id="2" ... />
<child id="3" ... />
</content>
And manipulate ctx in webapp to change order of 1 and 2, and remove 3
<content>
<child id="2" ... />
<child id="1" ... />
</content>
After passing the Storage Object the resulting children on the stored content is 2,1,3
If I change to 3,2 the resulting children on the stored content is 3,2,3
So my conclusion are: child elements are inserted or updated in the storage processes - excising ones are not removed. Anyone have a workaround or tips?
I am thinking of doing an enabled attribute and set to false for all "excedeing" children but is seems like a very unnecessary step, and making the solution more complicated that needed.
For info, my code for manipulating ctx is as follows:
var ids = "2,1".split(",")
delete ctx.content.child
for(var i=0;i<ids.length;i++){
ctx.content.appendChild(<child id={i} ... />)
}
Views
Replies
Total Likes
Hello Jonas,
I'm not sure this is a good way to delete child elements from a XML.
Can you try to user the removeChild method instead of 'delete' instruction ?
Here a code but I'm not 100% sure (because iterate and delete from a list is always not simple... but as I use the element and not the index for removeChild, it should work ?)
var allChilds = ctx.content.getElements('child');
for(var i=0;i<allChilds.length;i++){
ctx.content.removeChild(allChilds[i])
}
Then you can add your new child.
Or if you want to replace a child, you can use 'replaceChild' function.
If it doesn't work I'll try on my side.
Cedric
Views
Replies
Total Likes
Dear Cédric, thank you for your kind reply. I get TypeError: ctx.content.getElements is not a function However I can do:
for(var i=0;i<ctx.content.child.length();i++){
ctx.test.child[i] = ctx.content.child[i]
// ctx.content.removeChild(ctx.content.child[i])
}
and ctx.test is populated, hower removeChild causes the same type of error. ctx.content.appendChild(<child ... />) seems to work fine thought. The mysterium deepens...
Views
Replies
Total Likes
hmmmmm, sorry, I thought that ct.content was a DOMElement. My bad. So yes, I've just checked, delete works for xml list, I was totally wrong, forget my message
I think I know where your problem is : you insert the value 'i' into the id child attribute.
But i is not the value of your array(["2","1"], but the index.
So, you insert <child id="0"/> <child id="1"/> and not <child id="2"/> and <child id="1"/> as expected
Just tried and saw this problem.
Changing by
ctx.content.appendChild(<child id={ids[i]}/>)
resolved the problem
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Hi @RBE_jonas,
Were you able to resolve this query or do you still need more help here? Do let us know.
Thanks!
Views
Replies
Total Likes
Views
Likes
Replies