2015-06-17 2 views
-1

Мне нужно показать общее количество getTotalPrice. Im получаю следующее сообщение об ошибке:Uncaught TypeError: currentCoffee.getTotalЦена не является функцией

Uncaught TypeError: currentCoffee.getTotalPrice is not a function.

function Order() 
{ 
    this.coffeeOrder = []; 
    // Array of coffees (Start with an empty array) 
    this.addCoffee = function(coffee) 
    // addCoffee() add a coffee to the array 
    { 
       this.coffeeOrder.push(coffee) 
    }; 
    this.getTotalPrice = function() 
    // getTotalPrice() is the combined prices of all coffees in the order 
    { 
     var total = 0; 
     for (var i = 0; i < this.coffeeOrder.length; i++) 
      { 
       total = total + this.coffeeOrder[i].getTotalPrice() 
      } 
      return total; 
     };  
} 

var order = new Order(); 

function display() 
{ 
// Remove the current display 
     $("#tablebody tr").remove(); 

     // Build the html display 
     var html = ''; 
     for (var i = 0; i < order.coffeeOrder.length; i++) 
     { 
      var currentCoffee = order.coffeeOrder[i]; 
      html += "<tr>"; 
      html += "<td>" + currentCoffee.collectionName() + "</td>"; 
      html += "<td>" +"R"+ currentCoffee.getTotal() + "</td>"; 
      html += "<td>" +"R"+ currentCoffee.getTotalPrice() + "</td>"; 
      html += "</tr>"; 
     } 
      // Append html to dom 
      $("#tablebody").append(html); 
} 

Что я могу сделать, чтобы исправить эту проблему? Благодарим вас заранее.

ответ

1

currentCoffee не имеет функции getTotalPrice. Похоже, вы хотите использовать order.getTotalPrice().

+0

Большое спасибо за ваш ответ. Это не шов, чтобы быть проблемой – christo360

+0

Это все, что у вас есть? Возможно, создайте [jsfiddle] (https://jsfiddle.net/) со всем исходным кодом. – Herku

Смежные вопросы