[英]How to push new items into lisview after socketio event is fired in nativescript
我創建了一個 socket.io 服務器來與我的 nativescript 應用程序一起使用。 它工作正常,但我遇到的問題是當“聊天消息”事件被觸發時,我想將新消息推送到列表視圖中。
這是我試過的
dataItems: new ObservableArray(),
onLoadMoreItemsRequested: function (args) {
console.log("---load more item---");
const that = new WeakRef(this);
const listView = args.object;
if (this._sourceDataItems.length > 0) {
setTimeout(function () {
that.get().addMoreItemsFromSource(25);
listView.notifyLoadOnDemandFinished();
socketIO.on('chat message', function (data) {
//console.dir(msg);
var toast = Toast.makeText("New Message");
toast.show();
this.dataItems.push(
{
sender: data.sender,
message: data.message,
date: data.date,
type: data.type
}
);
});
}, 1500);
args.returnValue = true;
}
},
我得到的錯誤是“無法讀取未定義的屬性推送”
請問我該如何解決這個問題
我使用了這個並且它起作用了
viewModel.dataItems.push(
{
sender: data.sender,
message: data.message,
date: data.date,
type: data.type
}
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.