I have a problem with the method removeChild - methods

I'm new here on Stackoverflow, started programming in January, small own applications could already be implemented and now I have a problem with JavaScript with the removeChild method, because I don't know how to use this method with other methods and functions can combine or must write.
Thanks in advance

Not really sure what you are trying to do, your question should be a bit more specific.
Just as an example, say you want to remove all items from a list, here's an example of what could be used.
var element = document.getElementById("top");
while (element.firstChild) {
element.removeChild(element.firstChild);
}
If you simply want to delete one child you would need to know the parent's Id, it is done like so...
var d = document.getElementById("top");
var d_nested = document.getElementById("nested");
var throwawayNode = d.removeChild(d_nested);
you can try the W3School documentation if you'd like
https://www.w3schools.com/jsref/met_node_removechild.asp

Related

In Parse.com cloud code, How to sort records by its child table

This question is about sorting by Pointer object in Parse.com cloud code.
I have an Class A object, and A.pointer is a Pointer object which point to Class B.
And I want to sort A in database by B.sortfield.
I've tried to use innerQuery like below, but seems not work.
var query = new Parse.Query(A);
var innerQuery = new Parse.Query(B);
innerQuery.descending('sortfield');
query.matchesQuery("pointer", innerQuery);
query.......
Could anybody tell me how to do it? tnx!
Found below answers, Parse does not support such query. It really disappointed me.
sort-a-query-based-on-a-data-in-another-table
and
rest-api-sorting-query-through-a-pointer

Making improvements to code

I have been working on a magento module for sometime now (not because it is a large module, its my first and I really struggled with it). I now have it working, which I was really pleased with at first, but now I would like to improve it by increasing the reusability of the code.
While making my module I have looked at other modules to learn from them and have seen that many actions are only a line or two and I have tried keeping in with the skinny controller approach but failed, my example is as follows:
I have a function that get a users details that they have inputted into a custom form
protected function _setPostData()
{
$this->_salutation = $this->getRequest()->getPost('salutation');
$this->_f_name = $this->getRequest()->getPost('f_name');
$this->_l_name = $this->getRequest()->getPost('l_name');
$this->_email = $this->getRequest()->getPost('email');
$this->_emailAddressCheck = $this->getRequest()->getPost('emailAddressCheck');
$this->_gender = $this->getRequest()->getPost('gender');
$this->_country = $this->getRequest()->getPost('country');
$this->_pref_lang = $this->getRequest()->getPost('pref_lang');
}
I feel that this is not the correct way to do it and that there is a better way of achieving the same goal, as you can see this function gets the posts data and assigns it to attributes that i've set at the start of the class. I have several other examples that are very similar to the above and if someone could please offer some guidance on this one I am sure I will be able to work out the others
This example is held within the index action, should I put it in a helper as once it created correctly i am sure there will be a few occasions that I will be able to use it again?
you should put all the post data on an array and use it from there
$dataArray=$this->getRequest()->getPost();
$this->_salutation = $dataArray['salutation'];
$this->_f_name = $dataArray['f_name'];
$this->_l_name = $dataArray['l_name'];

removeFilters(filters) : Ext.util.Collection

Can someone please explain to me how can I use removeFilters(filters) method from Ext.util.Collection?
I've seen a similar post here: Remove Individual Filters from Store in Sencha Touch 2.x but it wasn't very helpful to me.
I have a list of contacts and I want to filter it with 2 filters for example and after that to remove only one filter. For now, I have a store that gets the data from a file but I wil make it to read data from a server. Thanks.
No problem.
var oldFilters=[];
var newFilter;
var store = myList.getStore();
oldFilters = store.getFilters();
newFilter = oldFilters[1]; //get the second filter
store.clearFilter();
store.setFilter([newFilter]);
If you want you can keep the store from sorting to speed up things.

Qt: Using default model for selecting my data

I am quite new to Qt and am in a situation where I want to use a model for my needs:
I have a dynamic number of instances of a subclass that need to be handled differently (different UI controls for each if it is selected). I want to get a list view where I can add new elements or delete old ones, as well as disabling/enabling existing ones.
Of course I want to rewrite as least of the code as possible, so I thought of utilizing the Listwidget and a ListModel to give some controls to the user. But how to link these (or better the items) to instances of the classes?
Do you know any tutorials on this?
I already looked in QtDemo and Google but I do not know the right words to search for
so I had no good results.
Basically what I think I need is a model item that accepts Collider* for its data.
But when I plug this into QStandardItem.setData() it says error: ‘QVariant::QVariant(void*)’ is private
So I found the solution to this problem.
As QStandardItems are capable of storing QVariants as data I wanted to store a pointer to my data in a QVariant. To achieve this I had to use Q_DECLARE_METATYPE(MyType*).
With this I was able to
MyType *MyInstance = new MyType;
QVariant data;
data.setValue(MyInstance);
QStandardItem *item = new QStandardItem("My Item");
item->setData(data);
standardModel->appendRow(item);
And the best is you can add as many types you want and let QVariant do the work to decide if it contains the type you wanted:
if(v.canConvert<MyType*>())
//Yes it is MyType
else if( v.canConvert<MyOtherType*>())
//Oh it is the other one
So finally this only requires to declare the meta type so you do not have to subclass any items.
Also you should read on the limitations of this here:
Q_DECLARE_METATYPE
qRegisterMetaType
Does this page answer your questions? There's an example of deriving a StringListModel item that you might be able to use as a template

proper way of setting an attribute in Doctrine?

in some tutorials they tell you to set up an attribute like this:
$manager = Doctrine_Manager::getInstance();
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
and in the documentation it shows you this:
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
i wonder which one i should use? isn't it the latter one? cause how can you set an attribute to a singleton class in the first one? isn't the second one more correct?
Do you even understand the code you're looking at?
The first code is "wrong". First it assigns Doctrine_Manager object $managger, and then this variable is not used.
If you want to do more than one thing on Doctrine_Manager then it's natural to get assign this reference to something that won't mess up your code. If you want to do just one thing there is no need to use extra variable, in other words:
Doctrine_Manger::getInstance()->setAttribte(...);
or
$manager = Doctrine_Manger::getInstance();
$manager->setAttribute(...);
$manager->setAttribute(...);
$manager->doSth();
$manager->blahblahblah();

Resources