i am not able to iterate a json document in angular2 - json

i have just started angular2, and got a problem. I am not able to iterate a json document in angular2.data is coming from backend i tried many ways, also used elipses (?) operator but not working for me. Please help
i want to print name under area array

in your .ts code, try the following:
ngOnInit() {
for(let i = 0; i < this.country.length; i++) {
for(let n = 0; n < this.country[i].area.length; n++) {
console.log(this.country[i].area[n].name);
}
}
}
You should get a list of all the names in the console

First get the json as a string; then simply call JSON.parse(myJsonString) and you have your json-object
If you meant anything else please clarify, as I (and obviously others too) don't find your question formualted 100% clearly (for example, add some code or what you have tried before)

Related

adding a new class using a for loop to determine which class specifically to add

I made this account to ask this question because researching strings and testing a whole ton of different things ended up with nothing working. You should be able to see what I am trying to do with this code piece here that is not working for me. If I hard type out "Level1" instead of "Level[i]" everything works fine.
for (var i = 0; i<=100; i++)
{
if (levelOn == i)
{
var Lv:Level[i] = new Level[i];
addChild(Lv)
}
}
I have 100 level files labeled "level1", "level2", etc in the project folder. I am trying to access a certain level via using a forloop to add a certain level to the screen (levelOn = 56 means the compiler would add the class "Level56" to the screen.)
I think I have the right idea but I cannot get it to work, all I get is this error
Line 24 1086: Syntax error: expecting semicolon before leftbracket.
If someone has a more efficient way of accessing a "level" in a application (where it has the same base class but minor differences) please send me in the right direction.
Thanks!!!!!
Try this:
var i:int;
var Lv:Level[i] = new Level[i];
addChild(Lv)
for (i=0; i<100; i++){
if(LevelOn=i)
}

How to access html element text in chrome devtools console

I have a page with a whole bunch of blackquote tags.
In dev console I am typing document.getElementsByTagName("blockquote") that giving me an array.
But if I do document.getElementsByTagName("blockquote").innerText document.getElementsByTagName("blockquote").innerHTML document.getElementsByTagName("blockquote").textContent
document.getElementsByTagName("blockquote").outerText document.getElementsByTagName("blockquote").outerHTML
All return undefined
However if I inspect elements of the array document.getElementsByTagName("blockquote") I can see all above properties in place.
How to access at least one of them (innerText, outerHTLM, innerText, outerHTML, textContent) ?
Or if you want to access any specific element you can use index in array
for (var i=0; i <document.getElementsByTagName("blockquote").length; i++ ){
var singleElement = document.getElementsByTagName("blockquote")[i];
console.log(singleElement.innerHTML);
}
You need to iterate the array in order to access those properties. Something like this will work for them:
var elements = document.getElementsByTagName("blockquote");
for (var prop in elements)
{
if(elements.hasOwnProperty(prop)) {
console.log(elements[prop].innerHTML);
}
}
You can also try the following commands:
var elements = document.getElementsByTagName("blockquote");.This will return the list of elements.To access the text of your required element at i index
elements[i].value.

Highlight an array of nodes in Autodesk Viewer

Problem:
I have an array of nodes that I would like to highlight when an action happens.
My Attempted Solution
I have tried using code from the model browser, but it seems to only accept one dbId at a time. I have tried to iterate over my array and call it, but the highlighting doesn't work when that is done.
for (var i = 0; i < dbIdsArray.length; i++) {
viewerApp.getCurrentViewer().impl.rolloverObjectNode(dbIdsArray[i]);
}
Any advice on how to implement this correctly would be a great help.
Thanks
If you want to highlight a couple of dbids, there are some different ways depending on your requirement.
Maybe you can use the API Viewer3D.isolate() to highlight the
selected objects by isolating them, you can just input dbId array as
follow, also, you can zoom the selected items to the viewer window
use the API Viewer3D.fitToView() to focus on them:
viewer.isolate(dbIdArray);
viewer.fitToView(dbIdArray);
If you want to highlight the selected objects with different color,
maybe you can try the new API Viewer3D.setThemingColor(), here is the
simple code sample. Remember you need to clear the color using
Viewer3D.clearThemingColors(). The simple code sample should be like:
I'm able to highlight components using following code:
viewer.addEventListener(
Autodesk.Viewing.SELECTION_CHANGED_EVENT,
function (e) {
if(e.dbIdArray.length) {
var dbId = e.dbIdArray[0];
viewer.impl.highlightObjectNode(
viewer.model, dbId, true, false)
viewer.select([])
viewer.impl.sceneUpdated(true)
}
})
This is using function:
viewer.impl.highlightObjectNode = function(model, dbId, value, simpleHighlight)

How can I loop JsonModel in sapui5?

I'm making my first app in sapui5.
I want create a login page with sign up and login.
In sing up I want save user name and password in a external JSON. How I can export the JSON Data?
In login I want validate password and username but i don't know how to loop the JsonModel.
I try this but of course didn't work.
var acountsJson = sap.ui.getCore().getModel("acountsModel");
for(var i = 0; i < acountsJson.length; i++) {
var obj = acountsJson[i];
console.log(acountsJson.id);
}
Can sap.ui.core has multiple Models?
Can sap.ui.core has multiple Models?
Yes, UI5-Core can hold multiple data models. In your case the model is named "acountsModel". You can add more models with different names.
Once you access your model, by sap.ui.getCore().getModel("acountsModel").getProperty("/"); you can either loop through an array using native for() or using jQuery:
$.each(acountsJson, function(value, index, array){
console.log(value.id);
});
Personally, I like the jQuery approach much more than the for-loop.
To get the JSON, you need to access your JSON Property, e.g. "/" for top node ...
var acountsJson = sap.ui.getCore().getModel("acountsModel").getProperty("/");
for(var i = 0; i < acountsJson.length; i++) {
var obj = acountsJson[i];
console.log(acountsJson[i].id);
}

How do I get the twitter api trends json data into flash as3?

So I know how to get json data into flash with twitter's search api because the array names normally aren't weird, but I'm not really too experienced with json. For the trends api data, I'm not sure how to access it because the array name is the date and theres spaces and colons in it, and I'm not really sure what to do. Normally in flash to get the json data I'd do something like
json.trends[0].2012-01-21 01:20.name
but that doesn't work. Can someone tell me how to pull out the name data when the array name is the date. I apologize if I'm calling these things the wrong name, I'm not too sure on what their proper names are.
To get a better understanding of what I'm talking about copy this link https://api.twitter.com/1/trends/daily.json into this site http://jsonformatter.curiousconcept.com/ in order to format the JSON.
I hope my question makes sense and thank you very much in advance.
var result:Object = JSON.decode(urlLoader.data);
var trends:Object = result.trends;
// trends in an object here, not array
// loop to find the properties in trends
for(var date:String in trends){
// date is a property of trends
// trends[date] is the value of property date
// trends[date] is an array
var items:Array = trends[date];
//for (var i=0; i<items.length; i++){
// var item:Object = items[i];
// loop in the array to get each item
for each(var item:Object in items){
}
}
Try this json.trends[0]["2012-01-21 01:20"].name
x.y is pretty much just syntactic sugar for x["y"]
Try json.trends["2012-01-21 01:20"][0].name
trends is not an array.
Also, you would have to look out for that the time value (that gives an array) will change over time.
I wonder why twitter has chosen this kind of odd structure, where you would have to somehow look up the date and time used in the data, rather than accessing the array the same way on each call? If someone knows or can guess why, please tell in a comment.
{
"trends":{
"2012-01-21 10:40":[
{
"name":"#IReallyLike",
"query":"#IReallyLike",
"promoted_content":null,
"events":null
},
{
"name":"SOPA Is Dead",
"query":"\"SOPA Is Dead\"" ...