is it not able to delete Child node directly? - removechild

I am a very beginner and code is like this:
function itemDone(e) {
var target, elParent, elGrandparent;
target = getTarget(e);
elParent = target.parentNode;
elGrandparent = target.parentNode.parentNode;
elGrandparent.removeChild(elParent);
is there any other way that I can delete the child element directly with any keyword rather than find parent and grandparent and then delete child element from parent.
thank you.

No, there is no way. You need to know the parent in order to remove the child. Unless you are dealing with double indirection which you would need pointers for and a different language.

Related

Eloquent relationship causes model nesting

I have the Eloquent BfsImages model defined with the following relationship:
public function listing()
{
return $this->belongsTo('App\CommercialPeople\Models\BfsListings', 'bfs_listing_id', 'bfs_listing_id');
}
And the attribute appended:
public function getPathAttribute()
{
return config('settings.bfs_image_path') . $this->listing->auth_agent_id . '/' . $this->filename;
}
As you can see the attribute refers to the parent model, so when I call the following:
BfsListings::with('images')->all();
Even though technically the relationship from images to listings is not called, because of that reference in the custom attribute BfsListing model is appended to images which causes model nesting so I get BfsListing->BfsImages->BfsListing.
My question is, is there a way to refer to parent model without actually appending it and returning it's data? Or.. perhaps there is a better way to maybe pass a variable from the parent to the child so that it could be used without calling the relationship back again?
To be honest since all my models are cached I don't care that much about multiple queries back and forth, I just want to remove the unnecessary data from images model, however I could use some smart way around it to not duplicate the query.
Edit
its possible to refer to other models without using the relations like this:
$this->listing()->setEagerLoads([])->first()->auth_agent_id;
However this still means that the reference to the parent model will be made once, which again causes two level nesting (so basically problem is not solved, but in some cases this will help to avoid infinite loops).
I still can't figure out how to call the parent model without actually loading it again.
You can alias the parent -> child relationship then access the parent via the alias.
$a = $parent->child;
$b = $a->parent;

extjs 4 - get VS select VS query

I am working on ExtJS 4.2 now. There are 3 ways to access DOM elements - get, select, query.
I want to know the difference between them. Why three separate methods?
we have a question here: SVO
But it doesn't give me any clear answers. Looking for something specific / detailed answer.
Will be grateful if you can help with the explanation.
Thanks in advance :-)
EDIT based on answer below:
I am not much into jQuery so can't understand through comparison. Can anyone help me with the difference between an Ext.element and a composite element?
EDIT 2:
What is Ext.dom.Element? Any different from Ext.element? and if anyone could throw some light on "Ext.fx.Anim" package?
Ext.get
Ext.get is analogous to document.getElementById in that you can provide the ID of a DOM node and retrieve that element wrapped as Ext.dom.Element. You can also provide a DOM node or an existing Element.
// Main usage: DOM ID
var someEl = Ext.get('myDivId');
// Wrap a DOM node as an Element
var someDom = document.getElementById('myDivId');
someEl = Ext.get(someDom);
// Identity function, essentially
var sameEl = Ext.get(someEl);
Ext.query
Ext.query allows you to select an array of DOM nodes using CSS/XPath selectors. This is handy when working with custom components or data views and you need a more robust selection mechanism than DOM IDs.
// Get all DOM nodes with class "oddRow" that are children of
// my component's top-level element.
var someNodes = Ext.query('.oddRow', myCustomComponent.getEl().dom);
Ext.select
Ext.select is essentially Ext JS's answer to jQuery's selectors. Given some CSS/XPath selector, it returns a single object representing a collection of Elements. This CompositeElement has methods for filtering, iterating, slicing the collection.
Most importantly, the CompositeElement supports chainable versions of all methods of Ext.dom.Element and Ext.fx.Anim that operate on each element in the collection, making this method very powerful.
Edit 1: An Ext.Element represents a single DOM node, while an Ext.dom.CompositeElement represents a collection of DOM nodes that can be affected through a single interface. So, given the following example:
// Set the height of each table row using Ext.query
var tableRowNodes = Ext.query('tr', document.getElementById('myTable'));
Ext.Array.each(tableRowNodes, function (node) {
Ext.fly(node).setHeight(25);
});
// Set the height of each table row using Ext.select
var compositeEl = Ext.select('#myTable tr');
compositeEl.setHeight(25);
You can see how much easier it is to work with Ext.dom.CompositeElement.
Edit 2: Ext JS supports the concept of alternate class names. Think of them as shortcuts for commonly used classes. Ext.Element is the alternate class name for Ext.dom.Element and can be used interchangeably.
Ext.fx.Anim is a class representing an animation. Usually not used directly, it is created behind the scenes when performing animations on elements or components. For example, the first parameter of Ext.Component#hide is the animation target.

Get the Type of an object's children in silktest

Assume i have an object and it has lots of children.May i know how i can find their types?
I first used getChildren() to get the children and then used typeof() for each child.
Typeof always returns
Window.
I would like to find if they are DomTextField or DomLink etc and not Window.
Thanks
The easiest way is to use yourParent.FindAll(/DomTextField), this will give you all direct children, if you want to include all descendants, use yourParent.FindAll(//DomTextField).

Adding Xelement as a Sibling of Xelement without a Parent

I'm trying figure out if this is possible. Basically, I need to create an XElement and then add one or more siblings to that XElement, but without a parent. I'll add that list of XElements to a Parent later, but need some flexibility in building this and other lists of XElements before doing so. Is this possible?
So I would have something like:
Public items As XElement = <ItemA>Something</ItemA>
And then I need to add an element so that the result looks like:
<ItemA>Something</ItemA>
<ItemB>Something Else</ItemB>
That result is what I need to pass around as a single object. I've messed arounnd with IEnumerable(Of XElement), but there is no .Add.
Any thoughts?
then add one or more siblings to that XElement, but without a parent
That's not going to work, elements are only siblings because they share a Parent ...
You'll have to use a temporary parent that you later change or replace.
You can of course use any collection (List<XElement>) to keep a list that you later turn into a list of siblings. Not clear what your problem with that is.

Using Criteria to get only base types

I'm looking for way in Fluent NHibernate to get a list of all object of type PARENT
using criteria.
I have a father object and a derived child.
The father contains a list of childs.
The problem is that when I use:
ICriteria crit = session.CreateCriteria(typeof(Parent))
IList<Parent> myRes = crit.List<Parnet>()
NH return back the list of both parent elements and the derived children elements, which is "right" b/c that is what I've asked, but that is not what I need.
(the children elements should be only inside the father object, but since they are of type parent as well - since they derived from it... NH brings them as well using this method.)
How can I get the list of all my "father" elements without the derived children ?
This is from the first answer (#Stefan Steinegger's)
session
.CreateQuery("from Parent where Parent.class == :class")
.AddType(typeof(Parent));
It looks like I need something like that - but it doesn't work in Fluent NHibernate.
Thanks,
Dani
the question actually is: how do you determine if a Parent is a root parent? there are various approaches:
You keep your model and define: a root is a Parent that is not inherited and is not included in any other Parent.
The part "is not inherited" might be easy to determine, but is actually a poor definition. When using inheritance, you should actually not care if an object you get as a certain type is actually inherited or not, this is the nature of inheritance.
The part "is not included in any other Parent" is hard to find out in an efficient way.
You set a reference to an objects parent. A root is a Parent where its parent references null.
You derive your Root from a common Base class. A Child is not a Root anymore, and a Root is a Root.
I suggest to take the last option.
BTW: you can filter for the exact type, but only using HQL.
session
.CreateQuery("from Parent where Parent.class == :class")
.AddType(typeof(Parent));