如果使用 io.socket 从数据库 rethinkDB 检索数据,则 DataView Slickgrid 为空
DataView Slickgrid empty if data retrieved from database rethinkDB using io.socket
我试图在 DataView Slickgrid 中显示数据库 rethinkdb 中的数据,但 DataView 是空的。由于某种原因,它没有获取数据并显示它。
这是我的代码:
jQuery(function($){
var socket = io.connect();
// Create the DataView.
var dataView = new Slick.Data.DataView();
var options = {
editable: true,
enableAddRow: false,
enableCellNavigation: true,
asyncEditorLoading: false,
cellHighlightCssClass: "changed",
cellFlashingCssClass: "current-server"
};
//Create columns
var columns = [
{id: "Name", name: "Name", field: "Name"},
{id: "Quantity", name: "Quantity", field: "Quantity"},
{id: "id", name: "id", field: "id"},
];
// Pass it as a data provider to SlickGrid.
var grid = new Slick.Grid("#myGrid", dataView, columns, options);
var database=[];
var object=[];
socket.on('new message', function(data){
for (var i = 0; i < data.length; i++) {
object = data[i];
database[i]={
Name: object.Name,
Quantity: object.Qauntity,
id: object.id,
};
}
});
dataView.beginUpdate();
dataView.setItems(database);
dataView.endUpdate();
})
你能帮我解决这个问题吗?提前致谢!
var grid;
var database=[];
var object=[];
socket.on('new message', function(data){
for (var i = 0; i < data.length; i++) {
object = data[i];
database[i]={
Name: object.Name,
Quantity: object.Qauntity,
id: object.id,
};
}
dataView.beginUpdate();
dataView.setItems(database);
grid = new Slick.Grid("#myGrid", dataView, columns, options);
dataView.endUpdate();
dataView.refresh();
grid.render();
});
现在可以了。
我试图在 DataView Slickgrid 中显示数据库 rethinkdb 中的数据,但 DataView 是空的。由于某种原因,它没有获取数据并显示它。
这是我的代码:
jQuery(function($){
var socket = io.connect();
// Create the DataView.
var dataView = new Slick.Data.DataView();
var options = {
editable: true,
enableAddRow: false,
enableCellNavigation: true,
asyncEditorLoading: false,
cellHighlightCssClass: "changed",
cellFlashingCssClass: "current-server"
};
//Create columns
var columns = [
{id: "Name", name: "Name", field: "Name"},
{id: "Quantity", name: "Quantity", field: "Quantity"},
{id: "id", name: "id", field: "id"},
];
// Pass it as a data provider to SlickGrid.
var grid = new Slick.Grid("#myGrid", dataView, columns, options);
var database=[];
var object=[];
socket.on('new message', function(data){
for (var i = 0; i < data.length; i++) {
object = data[i];
database[i]={
Name: object.Name,
Quantity: object.Qauntity,
id: object.id,
};
}
});
dataView.beginUpdate();
dataView.setItems(database);
dataView.endUpdate();
})
你能帮我解决这个问题吗?提前致谢!
var grid;
var database=[];
var object=[];
socket.on('new message', function(data){
for (var i = 0; i < data.length; i++) {
object = data[i];
database[i]={
Name: object.Name,
Quantity: object.Qauntity,
id: object.id,
};
}
dataView.beginUpdate();
dataView.setItems(database);
grid = new Slick.Grid("#myGrid", dataView, columns, options);
dataView.endUpdate();
dataView.refresh();
grid.render();
});
现在可以了。