How can I find Nth element of an xml object - actionscript-3

I'm trying to get sub elements of elements of an xml file. I tried using nested loops such as:
for each (var tempNode:XML in menu_xml.elements())
{
if (tempNode.children().length() > 0)
however couldn't accomplish that. Even if this this code works it will get elements for limited stages.
How can I get sub elements one by one, or is there a simpler way to do this?
EDIT: Here's the sample xml content:
<mainmenu>
<home/>
<portfolio/>
<contact/>
<friends>
<bestfriends>
<joe/>
<karen/>
<bob/>
</bestfriends>
<otherfriends>
<john/>
<peter/>
</otherfriends>
</friends>
<animals>
<cat/>
<dog/>
<horse/>
</animals>
</mainmenu>
EDIT 2: I havent decided how to use these nodes. Say I'll parse them to an array. arr[3][0][0] should be joe.

Why don't you use E4X? Here you can find some explanations:
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e72.html

Related

Run through elements of an array HTML

I am new to HTML and I have to modify a certain snippet of code so that it meets my needs. Here is the snippet, in pseudocode:
<app-myapp *ngIf="true"
[exclude] = "[this.myUser.id]"
">
</app-myapp>
Now what I need to do is the following: I also have an array of numbers inside the attribute myUser of my class called excludedUsers, and I want to include all the elements of this array in the [exclude] array that I am passing to my app. Obviously this does not work: [exclude] = "[this.myUser.id, this.myUser.excludedUsers]", because this.myUser.excludedUsers is an array. I do not know if a ngFor could work here. Could someone help me?
It's actually quite simple. It's called spread syntax and it expands all elements of an array into an array declaration.
[this.myUser.id, ...this.myUser.excludedUsers]

How can I get the innerText of Dynamic Html tags using Puppeteer.js (node.js) in TripAdvisor?

How would I get all 10 comments located in this page with a loop or a Puppeteer function https://www.tripadvisor.com/Restaurant_Review-g294308-d3937445-Reviews-Maki-Quito_Pichincha_Province.html using innerText property?
The only solution I have come up with is getting the outerHTML of the whole container of comments and then try to substring to get all the comments, but that is not optimal and I think its a more difficult approach. Maybe there is an easier solution in Puppeteer I cant find?
I am doing this for educational purposes. The comments are in class="partial_entry" and I want to get the innerText of a Dynamic Html tag (I want all 10), like the ones you see here:
If I where to open the div that contains <div class="review-container" data-reviewid="606551292" data-collapsed="true" data-deferred="false"><!--trkN:3-->, I would get another with id="review_582693262". Getting to the point, If I get to a <div> that has class="partial_entry" this would be where my comment is located. I have tried a few things but I get null, because it is not found since the parent <div> for each comment has a unique id like id="review_xxxxxxxxx".
Its kind of difficult since the review id is autogenerated like id="review_xxxxxxxxx" and cant iterate with a loop copying the CSS path since I dont have a static parent .
Why not just select those elements which have partial_entry class? This works:
let comments = await page.evaluate(() =>
[...document.querySelectorAll(".partial_entry")].map(item => item.textContent)
);

How to use Archetype with Razor?

I can't believe I couldn't find examples online.
This is my simple Archetype.
This is what I tried:
<img src="#CurrentPage.ctaTopLeft.image" alt="#CurrentPage.ctaTopLeft.text">
but it gives this error:
'Archetype.Models.ArchetypeModel' does not contain a definition for 'image'
EDIT: This works:
<img src="#CurrentPage.GetPropertyValue("ctaTopLeft").Fieldsets[0].GetValue("image")" alt="#CurrentPage.GetPropertyValue("ctaTopLeft").Fieldsets[0].GetValue("text")">
Wondering if there is any shorter way of writing it?
Well, no - an Archetype property can have a complex, nested set of data quite often in collections which may also be nested. In fact, it's quite common to use a corresponding nested set of partial views just to render it out correctly if you have for example nested Archetype properties (it happens).
There are some tutorials/samples available for this sort of thing:
http://imulus.github.io/Archetype/ - Archetype home on Github
https://gist.github.com/kgiszewski/8863822 - this one is linked from the Archetype page above - gives some examples of usage with Razor/MVC.
There are also other packages designed to help you map Archetype properties to POCO as well - e.g. https://our.umbraco.org/projects/developer-tools/archetype-mapper/
I prefer the typed way of getting the properties.
var property = Model.Contet.GetPropertyValue<ArchetypeModel>("yourArchetypePropertyAlias");
if (property != null && property.Any()) {
foreach (var item in property) {
var imageId = item.GetValue<int>("yourImagePropertyAlias");
var text = item.GetValue<string>("yourTextPropertyAlias");
}
}

jquery get elements by class name

I'm using Jquery to get a list of elements having a class "x".
html:
<p class="x">Some content</p>
<p class="x">Some content#2</p>
If we use Jquery to get both these html elements and do something with it- we use something like:
$(".x").text("changed text");
This will change the text of both the paragraphs. From $(".x") - How can we add a array - subscript notation like we can do with getElementsByclassName as follows:
document.getElementsByClassName("x")[0].innerHTML
I tried this
$(".x")[0].text("asasa")- it doesn't work gives a typeerror in javascript console. I also tried get API here -http://jsfiddle.net/probosckie/jnz825mp/ - and it doesnt work
the error is Uncaught TypeError: $(...).get(...).text is not a function
None of the solutions below WORK!
You can use the get() method for accessing an element from the array, for example:
$(".x").get(index).textContent = "changed text";
More info: https://api.jquery.com/jquery.get/
And for obtaining HTML (innerHTML) you call the .html() function:
// This is equal to document.getElementsByClassName("x")[0].innerHTML
$(".x").get(0).innerHTML;
If you want to set the HTML, then just provide your HTML code inside the function call like this .html('<h1>Hello, World!</h1>').
EDIT: .get() returns the DOM object not the jQuery wrapped element. Therefore .text() and .html() doesn't work. Unless you wrap it.
More options:
$(".x").get(0).innerHTML;
$($(".x").get(0)).html();
$(".x:first").html();
You can do it like this way:
$('.x:eq(0)').text('changed text');
or:
$('.x').eq(1).text('bbb');
both works well
sorry for my before answer..
The solution $(".x").get(index)... will first match all .x (which is bad performance). And then it will filter
If you have 1000 .x it will fill an 1000 items in the jQuery object (before filtered)
But
$(".x:first").text("changed text"); will do better because it won't yield all .x and then filter , but will do it at a first single step (without filling 1000 items)

Umbraco 7 Multiple Textbox pulling "System.String[]"

I am currently using Umbraco 7.1.8 and I have just finished my final template however I wanted to create a tag like list for the client to add in as they wish.
I have a multiple textbox with the alias workUndertaken however when I call it, it echos System.String[].
My code is pretty simple - I called it two different ways to ensure it wasn't an issue with one method.
<p>#Model.Content.GetPropertyValue("workUndertaken")</p>
<p>#Umbraco.Field("workUndertaken")</p>
Does anyone know where I am going wrong?
Sorry got the answer almost instantly. Was hard to find.
So I will post the answer with the code I am now using. Hopefully others find this useful.
#{
if (Model.Content.GetPropertyValue<string[]>("workUndertaken").Length > 0) {
<ul>
#foreach (var item in Model.Content.GetPropertyValue<string[]>("workUndertaken")) {
<li>#item</li>
}
</ul>
}
}