Socket.io 和 Extjs:為 Store 檢索數據 (Socket.io and Extjs: Retrieving data for Store)


問題描述

Socket.io 和 Extjs:為 Store 檢索數據 (Socket.io and Extjs: Retrieving data for Store)

Extjs Store 有沒有辦法以實時提要的方式從 Socket.io 獲取數據?沒有輪詢的地方。

我發現需要輪詢,我將使用 express 從 URL 獲取 json 格式的數據。我在想我然後做一個 setTimeout 來為 Store 加載。就像我說的投票一樣。

var app = express();

app.get('/getnames', function(request, response) {

    response.json({data:[{id:1,name:"John"}, {id:2, name:"James"}]});
});

還有其他方法嗎?

或者有什麼建議嗎?除了使用 setTimeout。

謝謝


參考解法

方法 1:

You dont need to use longpolling for websocket frameworks. All you need to do, is to listen events and write handlers. For example;

var socket = io.connect("localhost:8080");
socket.on("feed", function(data){
    myStore.loadData([data], true);
});

When you emit "feed" event from your socket.io server, above code will add the feed data to the store immediately. To emit data on your socket.io server with node.js;

io.emit("feed", {"id":123, "msg":"example feed"});

Of course, you have to write the logic that when someone(or your app) post a feed, it should emit a message to the server, and the server must emit this to the other clients. This way, all clients have a realtime feed viewer.

(by oneofakindabeyaz)

參考文件

  1. Socket.io and Extjs: Retrieving data for Store (CC BY‑SA 2.5/3.0/4.0)

#javascript #store #Socket.io #extjs #node.js






相關問題

為什麼我不能在 IE8 (javascript) 上擴展 localStorage? (Why can't I extend localStorage on IE8 (javascript)?)

在 Javascript 中打開外部 sqlite3 數據庫 (Open external sqlite3 database in Javascript)

Javascript:數組中的所有對像都具有相同的屬性 (Javascript: All Objects in Array Have Same Properties)

為什麼我們要在 javascripts 原型中添加函數? (Why do we add functions to javascripts prototype?)

顯示 URL javascript 的最後一部分? (Display the last part of URL javascript?)

Javascript XMLHttpRequest:忽略無效的 SSL 證書 (Javascript XMLHttpRequest: Ignore invalid SSL Certificate)

有沒有辦法測試 console.log 整體 (Is there a way to test for console.log entires)

如何從 javascript 對像中獲取名稱和值到新列表中? (How to get name and values from a javascript object into a new list?)

數據未發布..幫助!html,js,firebase (Data not posting.. Help! html,js,firebase)

使用 Node.js 腳本查看表單數據 (Seeing form data with Node.js script)

使用百分比查找範圍內的值 (find the value within a range using percent)

如何通過 react.js 中的組件傳遞變量或數據? (How to pass varible or data through components in react.js?)







留言討論