我在 javascript 中创建了一个名为 QuoteProductService() 的“类”,见下文。我在原型中添加了两个函数,现在,我试图从另一个函数 (getFakeQuoteProducts) 内的 jquery $.each 中调用其中一个函数 (getQuoteProductFromArray)。这行不通。我尝试添加“this.”,但这也不起作用,因为 .each 中的“this”指的是循环中的当前元素。
我该怎么做?
function QuoteProductService() {
}
QuoteProductService.prototype.getQuoteProductFromArray = function(quoteproductarray, quoteproductid){
var founditem=null;
// do stuff
return founditem;
}
QuoteProductService.prototype.getFakeQuoteProducts = function(){
// do something to fill the mappedQuoteProducts array
$.each(mappedQuoteProducts, function (index, quoteproduct) {
if (quoteproduct!=-null) {
if (quoteproduct.parentid != "") {
// this is where it goes wrong :
var parent = getQuoteProductFromArray(mappedQuoteProducts, quoteproduct.parentid);
if (parent != null) {
parent.attachChild(quoteproduct);
}
}
}
});
}