Iterating the JSON inside JSON in Angular2 - angular2-routing

Hi I am very new to the angular2 I want to iterate the JSON inside JSON objects
My JSON is shown below
{"items":[{"id":564,"sku":"MB570Z\/B","name":"Mini DisplayPort to DVI Adapter","attribute_set_id":4,"price":2800,"status":1,"visibility":4,"type_id":"simple","created_at":"2017-08-31 04:49:57","updated_at":"2017-08-31 05:06:31","weight":1,"extension_attributes":[],"product_links":[],"tier_prices":[],"custom_attributes":[{"attribute_code":"description","value":"Every Mac with a Mini DisplayPort allows you to connect an external display or projector using an adapter. You can use an external display as your main workspace or to extend your desktop, or you can work in mirrored mode with a projector so you can view what your audience sees.\r\nUse the Mini DisplayPort to DVI Adapter to connect an advanced digital monitor, such as the 20- or 23-inch Apple Cinema Display, that includes a DVI connector. Review the documentation or check with the manufacturer of your monitor to make sure you're choosing the right adapter."},{"attribute_code":"short_description","value":"Mini DisplayPort to DVI Adapter"},{"attribute_code":"image","value":"\/m\/i\/mini_displayport_to_dvi_adapter.jpg"},{"attribute_code":"small_image","value":"\/a\/p\/apple_hdmi_to_dvi_adapter.jpg"},{"attribute_code":"thumbnail","value":"\/a\/p\/apple_hdmi_to_dvi_adapter.jpg"},{"attribute_code":"options_container","value":"container2"},{"attribute_code":"required_options","value":"0"},{"attribute_code":"has_options","value":"0"},{"attribute_code":"url_key","value":"mini-displayport-to-dvi-adapter"},{"attribute_code":"msrp_display_actual_price_type","value":"0"},{"attribute_code":"tax_class_id","value":"2"},{"attribute_code":"gift_message_available","value":"0"},{"attribute_code":"is_featured","value":"0"},{"attribute_code":"gst_source","value":"28"},{"attribute_code":"hsncode","value":"85444299"},{"attribute_code":"gst_source_after_minprice","value":"-1"}]},{"id":565,"sku":"MB571Z\/A","name":"Mini DisplayPort to Dual-Link DVI Adapter","attribute_set_id":4,"price":9400,"status":1,"visibility":4,"type_id":"simple","created_at":"2017-08-31 04:49:58","updated_at":"2017-08-31 05:06:31","weight":1,"extension_attributes":[],"product_links":[],"tier_prices":[],"custom_attributes":[{"attribute_code":"description","value":"Every Mac with a Mini DisplayPort allows you to connect an external display or projector using an adaptor. You can use an external display as your main workspace or to extend your desktop, or you can work in mirrored mode with a projector so you can view what your audience sees.\nUse the Mini DisplayPort to Dual-Link DVI Adaptor to connect your Mac to a 30-inch display that includes a DVI connector, such as the 30-inch Apple Cinema Display HD, and enjoy the ultimate widescreen canvas with a resolution of 2560 by 1600 pixels."},{"attribute_code":"short_description","value":"Mini DisplayPort to Dual-Link DVI Adapter"},{"attribute_code":"image","value":"\/m\/i\/mini_displayport_to_dual-link_dvi_adapter.jpg"},{"attribute_code":"small_image","value":"\/m\/i\/mini_displayport_to_dual-link_dvi_adapter.jpg"},{"attribute_code":"thumbnail","value":"\/m\/i\/mini_displayport_to_dual-link_dvi_adapter.jpg"},{"attribute_code":"options_container","value":"container2"},{"attribute_code":"required_options","value":"0"},{"attribute_code":"has_options","value":"0"},{"attribute_code":"url_key","value":"mini-displayport-to-dual-link-dvi-adapter"},{"attribute_code":"msrp_display_actual_price_type","value":"0"},{"attribute_code":"tax_class_id","value":"2"},{"attribute_code":"gift_message_available","value":"0"},{"attribute_code":"is_featured","value":"0"},{"attribute_code":"gst_source","value":"28"},{"attribute_code":"hsncode","value":"85444299"},{"attribute_code":"gst_source_after_minprice","value":"-1"}]}],"search_criteria":{"filter_groups":[],"page_size":2},"total_count":91}

You need to do something like:
<div *ngFor="let item of items">
// you can access your item here for example
<h1>item.id</h1>
// and you can loop again
<div *ngFor="let temp of item.custom_attributes">
<p> temp.attribute_code</p>
</div>
</div>
You can use *ngFor to iterate over an array of objects

In your component.js,
private myItems:any = [];
constructor(){
}
yourFunction(){
let vm = this;
items.forEach(function(val: any){
val.custom_attributes.forEach(function(myAttrs: any){
vm.myItems.push({
"code": myAttrs.attribute_code,
"description": myAttrs.value
});
});
});
}
In your html file
<div *ngFor="let myItem of myItems">
<p> Code: {{myItem.code}} </p>
<p> Description : {{myItem.description}}
</div>

Related

Telegram Web Apps method Expand isn't working

I found that the method Expand of window.Telegram.WebApp object isn't working in the Telegram client for Windows and IOS on computers and tablets.
How to increase the size of Web Apps frame for those devices?
function buttonOn(){
// do something on btn click
}
let main_page = document.querySelector('#main_page');
if (main_page){
window.Telegram.WebApp.expand() //expand window after page loading
window.Telegram.WebApp.MainButton.onClick(buttonOn) //set func on main button click
window.Telegram.WebApp.MainButton.setParams({'text': 'Корзина'}) // set byn params
window.Telegram.WebApp.MainButton.show() //show telegram btn
}
Other button events
Remove the line from the function:
window.Telegram.WebApp.expand() //expand window after page loading
And call it in the beginning/at the top of your main javascript code. (The code that will start running once the user has clicked on the button)
Also, you can make your code a lot shorter by putting window.Telegram.WebApp in a variable like:
const tele = window.Telegram.WebApp; //Initializes the TELEGRAM BOT and
//Gets the user's Telegram ID from the Telegram API
tele.expand(); //Expands the app on the users' phone to 100% height
The reason is, probably, you are a bit incorrect in understanding what "expansion" is. This term could only be applied to mobile devices with OS such as Android or iOS. Web App is displayed there in such native component as BottomSheet with inserted WebView containing your web application. Initially, in mobile devices, application is being opened minimized (not expanded). To make it use maximum allowed height of screen, you could call expand() method. It must work through window.Telegram.WebApp.expand().
In desktop or web versions of Telegram, Web App is displayed in separate component which is not allowed to change its size.
You could probably find more useful information about viewport and expansion here, or use alternative libraries, such as twa-bridge or twa-sdk

How to enable gamepad in desktop mode in aframe v1.0.4+?

AFrame has a lot of cool stuff built-in, like support for controllers like gamepads.
In their documentation they recommend using the component "tracked-controls" which in turn will select the correct device component according to what is available for the browser. This seems not to work at all for me when in desktop mode in aframe v1.0.4
I'm using
Chrome v81.0.4044.122 (windows)
xbox gamepad
aframe v1.0.4 (latest npm package as of writing this)
I can find the gamepad when querying the browser gamepad api directly.
I declare my entity like this: <a-entity mycomponent tracked-controls></a-entity>
I can then see that aframe then transform this to <a-entity mycomponent tracked-controls-webxr></a-entity> as explained in the docs.
In my custom component mycomponent I then want to listen for the gamepad events like so
events: {
"controllerconnected": function () {
log.info("controllerconnected");
},
"buttonchanged": function () {
log.info("buttonchanged");
}
},
But I never manage to get those events.
So I dug into the source code to see when aframe is attaching it's internal gamepad event listeners, and from what I can read it all boils down to a dependency on the variable isWebXRAvailable when in desktop mode AND the presence of component tracked-controls-webxr.
var isWebXRAvailable = module.exports.isWebXRAvailable = !window.debug && navigator.xr !== undefined;
That !window.debug will exclude just about every desktop browser?
So my question is then, are gamepads supposed to be supported in desktop mode at all?
Or have I totally missed to point on how to use this feature, and if so please point me in the right direction :)
tracked-controls is designed for spatially tracked controls like Vive Wands or Oculus Touch provided with VR headsets. There’s no out of the box support for traditional gamepads. You can use the Gamepad API to integrate manually or look at movement-controls

Wordpress React Blog Not rendering Images Properly

I am new in React. I am attempting to make a live feed from my wordpress site. I am having trouble rendering the images associated with each article.
In the code below I log the mediaSRC variable which I am storing the url of the image. When logging this the proper URL outputs to console. However when I try to create my Post object later on after the if statement, the mediaID is = to "NO IMAGE"
When I am rendering the POST the html img is showing img src="NO IMAGE"
<div className="main-feed">
{posts.map(function(post){
//mediaSRC is eventually going to by my <img src >
var mediaSRC ="NO IMAGE";
//post.featured_media will access the media ID of the image
var media = post.featured_media;
// if there is no image set mediaSRC to this string
if (post.featured_media ==0){
mediaSRC="MEDIA ID IS ZERO";
}
// if there is an image, set mediaSRC to the url of image
else{
j.ajax(React_Theme_Resource.url + "/wp-json/wp/v2/media/" +media)
.done(function(data){mediaSRC = data.guid.rendered; console.log(mediaSRC)})
.fail(function(){console.log("FAIL")})
.always(function(){})
}
//Create Post object NOTE : working without images
return <Post post={post} mediaID={mediaSRC} key={post.id} />
})}
</div>
You are getting your image via an ajax request, but the component is not updated with the new image source. There are a couple of issues here.
It is a bad practice to make ajax request in your render method. The best place for them (if you are not using Flux, Redux or other state management library) is in the constructor.
Secondly, you need to use .setState() (again, if you are using react state to manage the state of the component and the app) method to add the new image source to the component.
You can read more about react state here: https://facebook.github.io/react/docs/state-and-lifecycle.html

Tridion UI editing Multimedia components

I'm having a problem enabling multimedia components i.e. image components to be edited through Tridion UI. When I use a General Content Component that has an image field it works fine without any issues as I get the JSON objects below:
<!-- Start Component Presentation: { 'ComponentID' : 'tcm:15-5444', 'ComponentModified' : '2012-12-27T12:07:29', 'ComponentTemplateID' : 'tcm:15-5364-32', 'ComponentTemplateModified' : '2012-12-27T11:30:49' } -->
<div><!-- Start Component Field: {'XPath' : 'tcm:Content/custom:Content/custom:image[1]'} --><img src="/Preview/_images/15-5366Hero%20Banner.jpg" alt="Banner SE"></div>
However When using an Image Schema Component directly with a Component Template the following tags are output:
<!-- Start Component Presentation: { 'ComponentID' : 'tcm:15-5366', 'ComponentModified' : '2012-12-18T13:21:46', 'ComponentTemplateID' : 'tcm:15-5364-32', 'ComponentTemplateModified' : '2012-12-27T11:30:49' } -->
<div><!-- Start Component Field: {'XPath' : 'tcm:Content/custom:Content/custom:Component.ID[1]'} --><img src="/_images/15-5366Hero%20Banner.jpg" alt="Banner SE"></div>
I know that I may not need to use "custom:Component" as this doesn't exist in the XML but can you see what I am doing wrong? Has anybody had any experience using a Multimedia Component directly on a page and been able to have the left hand image selection sidebar display?
Regards,
Billy
The markup you pasted is about inline editing of Component fields.
You can't use it for anything else.
You can inline edit the Metadata fields of an image Component in the Tridion UI, but you cannot upload a new version of the image. For that you will need use Open in Form View.
To get the Library Panel in Experience Manager (XPM), from the Home tab select Insert Content > Insert Content to get access to the left-hand images.
Your images' multimedia schema needs to have an associated Component Template (this is set in the Component Template's Linked Schema). Though you seem okay since you have the image as a Component Presentation already.
At least on my VM, the thumbnails appear automatically.

stoping flash file from running more than one time

I am working with a flash-template to create a website. I have a master page with a flash header and flash menu. when my home pages runs the flash header runs. the flash file should just run once but it is running each time I click on the menu items. I tried to use updatepanel, but i didn't know how to set the updatemode since my menu is working with flash. any idea of what i should use???
Store some data in the client that says they've viewed the flash before. When you execute your flash file, check for the existence of this data, and react accordingly. You may want to peak at http://www.flash-db.com/Tutorials/saving/ on how to save data.
You could use local storage, as shown here :
Write it as :
import flash.net.SharedObject;
var so:SharedObject = SharedObject.getLocal("userData");
so.data.isUsed= "true";
so.flush(); // writes changes to disk
Read it as :
import flash.net.SharedObject;
var so:SharedObject = SharedObject.getLocal("userData");
var isUsed = so.data.isUsed;
If it's a website page you may also use ExternalInterface.addCallback to add a function which can be called from javascript.

Resources