Добавление нового элемента в новый объект, а затем распечатка нового объекта в javascript
Hi all I am a newbie in JavaScript, i am stuck with this problem hopefully anyone can help out thank you . I am trying to create an Application where allow the user to input what kind of food , price that the customer have consume in a restaurant. First the User is required to key in the name of the User . Then when he or she click the" input name" button a new user object is created. I have created a constructor call UserCustomer(). when a new object is created , it will create element inside such as the customer name, price, and a remove user button, if the user want to remove the customer from the list. After the User click the input name button.the user will be navigate to the Add food page. The user is required to input the food and price which the customer consume,the user can add as many as he wants, when the user click the add Food Button , the program will push the food and price enter into the new customer object created previously.
Когда пользователь нажмет кнопку "Готово добавление". программа запихнет все значения в массив "newMakanUser".
И тогда, наконец, функция напечатает цикл через этот "newMakanUser" и распечатает значение
Результат, который я получаю, равен 0: [object Object] 1: [object Object]
Результат, который я хочу получить, таков
например
Джон еда :Бургер фри кола цена :2.4,1.5,1.0 Линда еда : салат Фруктовый сок цена : 3.5, 1.0,1,6
Что я уже пробовал:
//This is a New Array var newMakanUser = []; var newButton = []; var placeHolder = []; var TempVar=[]; var TempUSer= ""; function UserCustomer(nameU){ this.nameUser = nameU; this.Food = []; this.Price= []; var button = document.createElement("button"); button.innerHTML = "Remove " +nameU +" from list "; // 2. Append somewhere var body = document.getElementsByTagName("body")[0]; body.appendChild(button); } function outArray() { newMakanUser.toString(); newButton.toString(); function displayArrayObjects(arrayObjects,outputName) { // First Check the Array Length var len = arrayObjects.length, text = ""; this.outputName = outputName; //Loop through the Array for (var i = 0; i "; document.getElementById(outputName).innerHTML = text; displayArrayObjects( newMakanUser,"outputArray"); } // This Function is to create an object and store it inside an array. function addName(UserName){ // Get the User Input Object product name UserName = document.getElementById("NamePax").value; TempUSer = UserName ; TempVar.push(new UserCustomer(UserName)); // alert( "Hello"); // newMakanUser.push(new myUserName(createProduct,productprice)); slides.style.display = "block"; slidess.style.display = "none"; slidesss.style.display = "none"; } function addFoodPrice(Foody,Pricey){ Foody = document.getElementById("FoodyName").value; Pricey = document.getElementById("FoodyPrice").value; TempVar.Food.push(Foody); TempVar.Price.push(Pricey); } function doneAdd(){ newMakanUser.push(TempVar); slides.style.display = "none"; slidess.style.display = "block"; slidesss.style.display = "block"; // document.getElementById("outputDB").innerHTML = text; } // This Function will remove the unwanted object Who Order the Food Person Name: Food Name : Food Price :