please i wanna to ask you about the result of this code , i couldn't understand the behavior of this on TypeScript
i have a json with two objects and when i wanna to display all the json Objects by this code
console.log(this.tabMenu)
i got this result
but when i want to select only title of the first object
console.log(this.tabMenu[0].title)
the result was empty !!!! but i want to display the title : Pizza
Please if you can help me to understant this ^^:
Regards
Related
To introduce me : I'm not developer, and I want to control the element is present in my json.
I have this type of json, and i want to control for exemple that "id = display-page" but I don't know how can I structure of my xpath to found it
"text": "{\"id\":\"display-page\",\"recoVideo_hasRecoLoaded\":\"\",\"recovideo_requiredEngine\":\"tp1top\",\"recovideo_executedEngine\":\"tp1top\",\"recovideo_fallbackEngine\":\"\",\"recovideo_abtestEngine\":\"\",\"recovideo_recoVideoId\":\"top-video-web-desktop-windows-PERSONA_DEFAULT\"
I try something like $..request.text.[?(#.name =='id')].value.display-page
but it doesn't work :(
Someone to help me ?
Thanks !
Antoine
I am relatively new to Angular, but I have a lot going on. Let me explain. I have an array of objects and a successful service running as shown below.
array of Objects
I have a input created as a search that is using the ngx-bootstrap TypeAheadModule so I can show typeahead values in the search. This is successful if I use a hard coded string array.
The html markup for the component shown below based on that ngx-bootstrap documentation.
<input [(ngModel)]="selected"
[typeahead]="points"
class="form-control">
This [typeahead] attribute looks to only accept a string array.
So here is my issue. I have an array of objects from my service, but I only need the name value from each object to fill what will become a string array for my search. I have been all over the internet looking for the best way to retrieve just a value from my array. I feel like I am missing some extremely simple.
Below is where I currently left it. I have my api call for points loading into a point array until I can figure out how to access the values inside the array.
points: Point[] = [];
this.service.getPoints().subscribe(response=> {
this.points = response as Point[]
});
This current returns [Object Object] in my TypeAhead. How can I access the values into my array and return them as a string array?
Thanks everyone!
try this.. I think you missed a div with ngFor
<div *ngFor="let point as points; let i of index">
<input [(ngModel)]="point[i]"
[typeahead]="point"
class="form-control">
</div>
your trying to print points array directly, I hope this approach will solve your issue.
I missed a small section on the ngx-bootstrap documentation. There is an additional attribute 'typeaheadOptionField' that lets you select the field out of a more complex object array.
This may be a little confusing to describe.
Basically, I am parsing multiple external JSON feeds that display in different views depending on the 'active tab' displayed. They both share the same partial template, so they both look exactly the same, just different content.
The problem that I am facing now is, that in some feeds, some keys are placed in an array and others are not.
For example, the feeds parses this kind of data:
JSON Feed 1 - One 'attributes' inside of 'link'
"link":{
"attributes":{
"href":"www.link1.com"
}
}
JSON Feed 2 - Two 'attributes' inside of 'link'
"link":[
{
"attributes":{
"href":"www.link1.com"
}
},
{
"attributes":{
"href":"www.link2.com"
}
}
]
The only way I am able to get the value "www.link1.com" is via:
For Feed 1:
link1
And for Feed 2:
link1
I am trying to figure out what would be the best way to do:
1) If link[0] exists - display it, else if [link] exists, display that instead.
2) Or if targeting the activeTab would be safer? For instance, if activeTab = view2 or view4, use [link][0], else if activeTab = view1 or view3 use [link], else if I do not want it to be displayed, do not display anything.
Also a relatable question, if I am on view2 can I only display [link][0] on that view?
Any feedback would be appreciated. Thanks!
In your model controller, you can reconstruct the JSON objects to make them similar. The value of link in both feeds should be an array.
Then in your template you can simply use ngRepeat to get the items from inside the array.
Okay - so I found a solution to one of the questions above: "How to only display [link][0] in a specific view"
Pro: It's a simple code that depends on the activeTab / view that is being displayed.
Con(?): Since I am really a newbie to AngularJS - not sure if this is the best solution.
Basically:
Depending on the ng-view that is currently displayed, than a specific JSON object will be displayed, such as:
<a ng-show="activeTab == 'view1' || activeTab == 'view3'" ng-href="{{item['link'][0]['attributes']['href']}}">
<h6>Link1 from Feed2</h6>
</a>
Although the primary question is still unresolved: How to swap/switch JSON objects (key,values) if one exists, and not the other. I am still definitely trying to find a solution, although any help is still appreciated.
Please let me know what you think, or how I can improve the solution to the problem!
Thanks!
Roc.
I have got a problem. I am trying to display chart with PHP and my chart code is like this.
Database code
$rowval=$sqcat1->qcategory;
$per=($sqcat1->point_value*100)/($sqcat1->r_count*5);
and chart code
$data3['$rowval'] = $per;
$mc3 = new maxChart($data3);
$mc3->displayChart('Chart',1,500,600,true);
I actually want to pass the value like this
$data3['Windows']=80;
$data3['linux']=10;
$data3['Mac']=10;
etc extracting the data through the database.
I already try it doing like this
$data[$sqcat1->qcategory]= $per;
$mc3 = new maxChart($data);
$mc3->displayChart('Chart',1,500,600,true);
Its displays chart with percentage only not with the category and percent.
I want to display the category as well as percentage.
somebody please help me.
Can you try this
$rowval=$sqcat1->qcategory;
$data["$rowval"]= $per;
$mc3 = new maxChart($data);
$mc3->displayChart('Chart',1,500,600,true);
Please note the double quotes $data["$rowval"]
I'm using the Last.fm API to return data in JSON format and this works fine. I'm using the user.getTopArtist() API call.
As the page loads, a DIV object is created for each artist containing relevant details from the JSON data. When a user performs an action with the DIV I basically want to swap the image url to show a bigger image size!
How can I find/reference a JSON object by matching it's stored value?
For example, if I need to match the artist name 'Kate Bush' and then retrieve the "extralarge" image url. How would I do this?
The data structure looks like this:
{"topartists":{
"artist":[{
"name":"Kate Bush",
"playcount":"20",
"mbid":"4b585938-f271-45e2-b19a-91c634b5e396",
"url":"http:\/\/www.last.fm\/music\/Kate+Bush",
"image":[
{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34\/224740.jpg","size":"small"},
{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64\/224740.jpg","size":"medium"},
{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/224740.jpg","size":"large"},
{"#text":"http:\/\/userserve-ak.last.fm\/serve\/252\/224740.jpg","size":"extralarge"},
{"#text":"http:\/\/userserve-ak.last.fm\/serve\/500\/224740\/Kate+Bush.jpg","size":"mega"}
]
}
}
What are you using to parse JSON?
Here's a jQuery example http://api.jquery.com/jQuery.parseJSON/
If it is just for this particular task then that $.each(data.topartists.artist[0].images) approach would work.
As of more generic solution... Take a look on http://goessner.net/articles/JsonPath/ - that is XPath variant for JSON