Display Array with Navigation Data in CakePHP View - arrays

I have an Array to be displayed in a CakePHP View which contains the navigation data. Each array item contains fields like id, name, level etc. as well as another array field named children, where this structure repeats.
In the Cake PHP View it's easy to walk over the array on the first level with a foreach loop and the html-Helper to output the relevant data. But how do I ouput the child items (and then their children if present)? Normally I would do a recursive function call, but within the view you shouldn't use function look, should you? Bunt within the controller I cannot use the html helper, so I'm stuck here.

I think as a clean solution to make a helper to iterate over the array an recursively look for each elements if one of them another array (http://book.cakephp.org/#!/view/1097/Creating-Helpers)
Or if you know that your item could has one and only one child, you could ask if the actual item is an array an operate it. But I prefer the first solution.

It looks like you might try the tree behavior
http://book.cakephp.org/#!/view/1341/Basic-Usage

you need something like a recursive method that can call it's self, something like the following. https://github.com/infinitas/infinitas/blob/beta/core/menus/views/helpers/menu.php#L163

Related

How to delete a piece of data from an array inside a Nested Collection?

I want to delete an item from an array that is inside a collection that is inside another collection (A nested collection) I have all the data that I need to achieve this, however I do not know how to write I have a slightly idea of how to (I'll be testing stuff on my own, but will leave the question here as well)
I'm using Material UI DataGrid to render my tables and to delete/edit them. I have a piece of information that is saved on my Local Storage in case I required it:
this is how my table looks:
When I select an ITEM and delete it is holding the ID of the item in the data:[Array]
those IDs are the IDs they hold in the data[array] -> :
finally I need to access this document, well I have the following
db.collection("usuarios").doc(user.uid).collection("pedidos").doc(id)
which brings the following:
which means I'm bringing the correct document, however I have no idea how to "update" or delete the array called data[], any ideas? What I want to achieve is that when I press the delete button it will update the array based on the Item selected so if it was Item ID: L-2627 then go through the array inside that collection, get the array called data and delete the item stored in the array.
Read the document into memory.
Modify the array by finding the item and removing it, again from memory.
Write the modified contents back to the document.
There is no shortcut or single operation for doing any this. The fact that the document is in a subcollection doesn't change anything. It's just how you have to modify arrays when you don't know the entire contents of the array item ahead of time.

Drupal 7 - Render view after views_get_view_result

How do I render the view result that I get by calling "views_get_view_result"
So right now I have:
$variables['result'] = views_get_view_result('name', 'name-block');
And it returns an array of Object, which is what I want. Just can't figure out how to render it. Trying to render $result[0], $result[1] for example.
Thanks,
Tee
For a simple way of doing this, use
print views_embed_view('view_name', 'display_id');
which is a utility function for doing what you want to do. See https://api.drupal.org/api/views/views.module/function/views_embed_view/7
Here is a thread with additional ways of doing this, if you need the extra complexity / depth. https://drupal.org/node/951442

Array won't refresh itself after removeChild

There is an array of objects. I'm trying to removeChild an object from that array like below. removeChild works fine but the array won't refresh itself after removing uppest object. As you can see in below, i tried to trace array items out.
Firstly, array has three items, obviously the myArray.length must be 3.
After removing a child, myArray.length must be 2, but it get 3 (Wrong).
removeChild(myArray[currShape]);
trace(myArray);
Please tell me what am i missing here.
Assuming you're using ActionScript, removeChild() only serves to take objects off the stage. It doesn't take things out of an array. You have to take the object out of the array manually in another statement.
You could try something like:
removeChild(myArray.splice(currShape,1));
This removes the entry from the array and returns that entry that will be used to remove it from the stage.

How to use (find)where in backbone to get a specific field of an array

I use to use the where method from the Collections in backbone. But I don't see how to fetch this result:
MyCollection.Group[x].id
As you can guess, MyCollection is the collection, Group is an array, and id is the field I would like to match for a specific value, something like:
MyCollection.findWhere(Group[x].id: 34);
I have seen the "contains" function of underscore but it doesn't seems to work with associative arrays
Is there a way to do it or should we parse the collection manually using Javascript ?
Collection.where and Collection.findWhere are convenience functions for simple filters. In your case, you would use the more complex Collection.find (proxied to _.find)
find _.find(list, iterator, [context])
Looks through each value in the list, returning the first one that passes a truth test
(iterator). The function returns as soon as it finds an acceptable
element, and doesn't traverse the entire list.
And if I understand correctly your condition, it could look like
MyCollection.find(function(model) {
return _.findWhere(model.get('Group'), {id: 34});
})
you can choose to use jQuery .find() . see examples here: http://api.jquery.com/find/

How to easily grab an array of children from a batch node by tag

I know that I can get an array of all the children of a CCSpriteBatchNode by using its children property, but can I get an array easily of just the subset of children that share a common tag?
What I do now is:
Get the array of the children of the batch node
Make a new array for the children with the tag of interest
Iterate through the children, and if the individual child has that tag, add it to the new array
Seems kind of cumbersome so I thought there might be a way to to it easily. If you just want a single child, you can use getChildByTag I think...
That's the way to do it.
However you can (and should) initialize an array with the children that use the same tag in your class, and every time you add a child with that tag you'll also add it to the "childsWithTagX" array. Same for removing. That way you have an always up-to-date separate children array containing only nodes with a given tag.
I think I'll have to add this as a feature to the Kobold2D Roadmap. I needed that a few times already.

Resources