how can copy node to variable and use visit to remove some item? - fancytree

i use this code
var mdata = node//.toDict(function (n) {delete n.key});
mdata.visit(function (n) {
if(n.data.itemtype !=='folder')
n.remove();
});
when i remove items from mdata that's remove from original node
how can i copy node without any dependencies???
when i use toDict but i can't use visit to process node items
i use Object.assign({},node) and other methods but i can't do this
i need copy a node and paste that to other branch but remove some items before paste it

In order to copy and modify a node, use toDict:
var d = node.toDict(true, function(dict){
delete dict.key;
if( dict.data.foo ) {}
...
});
then add it to the new target, e.g.
targetNode.addChildren(d);

Related

SAPUI5 List Item context binding, get the next path

I have a table of list items (questions) and I want to be able to re-arrange them. See screenshot.
Currently, on the button down press, I can get the current binding context and I am getting that sequence property (001). What I want to be able to do is also be able to get the path of the next list items binding context (002 in this case).
Current code...
// Move Question Down
onQuestionMoveDown: function (oEvent) {
// Get binding context
var source = oEvent.getSource().getBindingContext("view");
var path = source.getPath();
var object = source.getModel().getProperty(path);
var currentQuestionSequence = object.Sequence;
MessageToast.show("Current # " + currentQuestionSequence);
}
Then once I have that I can sort my updates logic.
A possible solution could be that you have an order value on your model and you update that order when the user clicks on the button.
If the list is sorted by that value you will achieve what you're looking for.
The items should be bound to the table via list binding, and so the data set would be an Array, the path for each line will be like ".../itemSet/0, .../itemSet/1, ...". So possible solution could be:
function getNextItem(oItem){
var oContext = oItem.getBindingContext("view"), // assumpe the model name is view
sPath = oContext.getPath(),
sSetPath = sPath.substr(0, sPath.lastIndexOf("/")),
iMaxLen = oContext.getProperty(sSetPath).length,
iCurIndex = parseInt(sPath.substr(sPath.lastIndexOf("/")+1));
// If it's already reach to be bottom, return undefined
return iCurIndex < iMaxLen -1 ? oContext.getProperty(sSetPath + "/" + ++iCurIndex) : undefined;
}
Regards,
Marvin

Create an Array from list of objects in MaxScript and add them to a new layer

I'm super new to Maxscript and want to automate a process, I've been looking at some tutorials, but I'm running into a issue with selection. What I'm trying to do, is I have a list of strings (that I might have to add to) that represent objects in the max file that I want to select (if they exist in that file) and then add to a new layer.
for instance:
/* I have a big long list of objects I want to mass select, this has to be hardcoded because its a similar list that exists in a ton of max files */
rObj1 = "testObj1"
rObj2 = "sampleObj2"
""
rObj99 = "newObj90"
/*I want to then add it to an array
removeList = #(rObj***)
/* Then run through each entry in the array to make sure it exists and then add it to my selection
for i in removeList do
(
if i != undefined then select (i)
)
/*Then Add what I have selected to a new layer
newLayer = LayerManager.newLayerFromName "removed_list"
for obj in selection do newLayer.addNode obj
I keep getting an error when it comes to selection, being new to Max I'm not sure what to do.
You are trying to select string where you should be selecting (or adding to the layer) an object:
newLayer = LayerManager.newLayerFromName "removed_list"
for objName in removeList where isValidNode (getNodeByName objName) do
newLayer.addNode (getNodeByName objName)

Swift: Indirect access / mutable

I need to go to a referenced structure:
class SearchKnot {
var isWord : Bool = false
var text : String = ""
var toNext = Dictionary<String,SearchKnot>()
}
When inserting, I need to update values in toNext dictionary. Because I want to avoid recursion, I do it in a loop. But there I need a variable which jumps from one toNext item to the other, able to change it.
var knots = toNext
...
let newKnot = SearchKnot()
knots[s] = newKnot
The last command only changes a local copy, but I need the original to be changed. I need an indirect access. In C I would use *p where I defined it as &toNext. But in Swift?
I found a solution. I remembered old pascal days. ;-)
I don't use the last reference, but the second last. Instead of
knots[s]
I use
p.knots[s]
For hopping to the next knot, I also use
p = p.knots[s]
and could use
p.knots[s]
again. Also p.knots[s] = newKnot works, because p is local not the entire term.

Reuse Meteor template - Isolating events

I tried:
Template.skillsSearch = $.extend Template.skillsSearch,
rendered: ->
Session.set('s' + #_id, null)
Session.set('searchFocused' + #_id, null)
#_id worked before, I think because it was inside an each statement. Now I do not have this loop and # is {}(no _id in the object).
Suppose I have this:
body
+myTemplate
+myTemplate
How could I get an unique id per template instance? Or, how can I make unique session keys when reusing a template?
This is how I solved it:
template(name='father1')
with 'father1'
+reusedTemplate
template(name='father2')
with 'father2'
+reusedTemplate
template(name='reusedTemplate')
h1 #{aVariable}
Then in coffeescript:
Template.reusedTemplate = $.extend Template.reusedTemplate,
rendered: ->
# Here #data contains whatever you pass in with
# i.e. 'father1' and 'father2' respectively
aVariable: ->
# Here # contains whatever you pass in with
# i.e. 'father1' and 'father2' respectively

OpenXml: Copy OpenXmlElement between documents

I have two Word documents (WordprocessingDocument), and I want to replace the contents of an element in the first with the contents in the body of the second one.
This is what I'm doing right now:
var docA = WordprocessingDocument.Open(docAPath, true);
var docB = WordprocessingDocument.Open(docBPath, true);
var containerElement = docA.MainDocumentPart.Document.Body
.Descendants<SdtBlock>()
.FirstOrDefault(sdt => sdt.SdtProperties.Descendants<SdtAlias>().Any(alias => alias.Val == containerElementName))
.SdtContentBlock;
var elementsToCopy = docB.MainDocument.Part.Document.Body.ChildElements.Where(e => e.LocalName != "sectPr"));
containerElement.RemoveAllChildren();
containerElement.Append(elementsToCopy);
Basically I get the container (an SdtBlock) from the first document using its alias to identify it, then get all the children of the second element (removing the SectionProperties which I don't want to copy) and then try to add those to the container element.
The problem is that I'm getting this exception:
Cannot insert the OpenXmlElement "newChild" because it is part of a tree.
When I invoke the last line on that code (the Append).
Any ideas on how can I achieve what I want?
You need to clone the element to copy containerElement.Append(elementsToCopy.CloneNode(true));
The elementsToCopy is still attached to it's original tree. So you would have to remove it's parents or copy them( to keep the original intact). I think there exists a removeParent() method.