Anyone good with typescript or have built an e-commerce website? Help please! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Anyone good with typescript or have built an e-commerce website? Help please!

Im trying to make the user be able to navigate in and out of the different categories but I cant figure out how, The categories are fetched from a database and I have a navbar displaying the different categories but I cant figure out how to navigate in and out of them, would appreciate any help that can point me in the right direction. Here is my code down below. Thanks class Category { categoryId : number; category: string; constructor(categoryId: number, category: string) { this.categoryId = categoryId; this.category = category; } get() { return this.category; } createNavItem(){ return '<a class="navbar-item" categoryId="' + this.categoryId + '">' + this.category + '</a>'; } } fetch ('http://localhost:8888/ECshop/service/index.php?_action=CategoryGetList') .then(function(response) { return response.json(); }) .then(function(myJson) { console.log(myJson); //alert(myJson.description); //console.log(JSON.stringify(myJson)); }) .catch(function (error) { console.log(error.message); }); var Categories = Array<Category>(); function CategoryGetList() { fetch('service/index.php?_action=CategoryGetList') .then(function(response) { return response.json(); }) .then(function(data) { console.log(data); for (let i=1; i<data.length; i++){ Categories.push(new Category(data[i].category_id,data[i].category)); } }) .then(function() { var html:string = ""; for (let i = 0; i<Categories.length; i++) { html += Categories[i].createNavItem(); } let navBar = document.getElementById('nav-categories') as HTMLInputElement; navBar.innerHTML = html; }) .then (function(){ var classes = document.getElementsByClassName('navbar-item'); for (var i = 0; i < classes.length; ++i) {

16th Dec 2018, 3:48 AM
rashidk
rashidk - avatar
2 Answers
0
Can you clarify "navigate in and out of them" Is it about displaying the items in that category Or about getting the data about those items in that category? If latter, can you provide some example of your data for our further study of your situation?
19th Dec 2018, 4:24 AM
Gordon
Gordon - avatar
0
If you are looking to build an e-commerce website with TypeScript, you will likely want to use a web framework that supports TypeScript, such as Angular, React, or Vue.js. Each of these frameworks has its own strengths and weaknesses, so it's worth doing some research to determine which one might be the best fit for your project. Read More: https://sparketing.eu/webdevelopment/webshop-laten-maken/
31st Mar 2023, 4:40 PM
Sparketing