2016-09-15 61 views
0

我试图在另一个函数中使用函数,但即使我事先声明了它,聚合物说它不是。我不明白。任何线索?在聚合物中声明函数

Polymer({ 
is: 'x-foo', 

//some other code here, including the properties.... 

computeRange: function (offset, limit, nodeRangeStart, nodeRangeEnd) { 
    nodeRangeStart.innerText = offset; 
    nodeRangeEnd.innerText = offset + limit; 
}, 
prevPage: function() { 
    this.offset = this.offset - this.limit; 
    computeRange(this.offset, this.limit, this.$.usersListRangeStart, this.$.usersListRangeEnd); 
    this.$.nextPage.removeAttribute('disabled'); 
    if (this.offset <= 0) { 
    this.$.prevPage.setAttribute('disabled', true); 
    this.$.prevPage.style.color = '#DDDDDD'; 
    }; 
} 

}); 

和控制台:

未捕获的ReferenceError:computeRange没有定义

回答

5

你试图调用computeRange(),好像它是一个全球性的功能,但它实际上是你的构造函数对象的一部分。你需要使用this

this.computeRange(...) 
+0

现在完美的工作!非常感谢,托尼! – SKMTH