onClick里面回调方法崩溃:
Js-Engine: ark
page: pages/Index.js
Error message: is not callable
SourceCode:
this.getNewsByChannelId(1, false);
^
Stacktrace:
onClick里面回调方法崩溃:
Js-Engine: ark
page: pages/Index.js
Error message: is not callable
SourceCode:
this.getNewsByChannelId(1, false);
^
Stacktrace:
该错误信息表明在pages/Index.js
文件的this.getNewsByChannelId(1, false);
这行代码中,this.getNewsByChannelId
没有被正确地调用。在JavaScript中,当一个函数作为对象的方法被调用时,this
关键字指向该对象。在这个错误中,this
可能没有被正确地指向包含getNewsByChannelId
方法的对象。
解决这个问题的方法取决于你的代码结构。如果你是在一个类或对象的方法中调用这个函数,你需要确保this
正确地指向那个类或对象。例如,如果getNewsByChannelId
是MyClass
的一个方法,你需要在类的实例上调用它,像这样:
let myInstance = new MyClass();
myInstance.getNewsByChannelId(1, false);
如果你在全局作用域或者某个函数中调用这个函数,并且你期望this
指向某个特定的对象,你需要使用.bind()
方法来绑定this
。例如:
let myObject = {
getNewsByChannelId: function(channelId, someBoolean) {
// your code here
}
};
let someFunction = function() {
myObject.getNewsByChannelId(1, false);
};
someFunction.bind(myObject)();
以上代码将确保在someFunction
函数中调用getNewsByChannelId
方法时,this
指向myObject
。
如果这些方法都不适用,那么你需要检查getNewsByChannelId
函数的定义,确保它确实是一个可以调用的函数。如果它是一个对象或类的方法,确保它在使用时被当作方法来调用(即后面紧跟括号)。如果它是一个函数,确保它在使用时被当作函数来调用(即后面没有括号)。
使用箭头函数传递
this(): viod => this.getListView()