Sails.js将键和数据stream传给Angular

我有一个angular度前端,从sails后端(使用sails-mysql适配器)填充数据到UI网格。 此数据集很大,需要一段时间才能在页面显示包含任何数据之前加载。

我有从风帆和运行stream的基本知识:

findAllStream: function (req, res) { Model.stream().pipe(res); } 

到目前为止,这将每个单独的数据从模型传输到前端。 我正在使用angular-oboe来使用这个stream:

 vm.myData = []; var obj = {}; var count = 0; Oboe({ url: '/api/model/findAllStream', pattern: '*', start: function(stream) { // handle to the stream vm.stream = stream; vm.status = 'started'; }, done: function(parsedJSON) { vm.status = 'done'; } }).then(function() { // promise is resolved console.log('done'); }, function(error) { // handle errors console.log('error'); }, function(node) { // node received switch (count) { case 0: obj['id'] = node; break; case 1: regObj['property'] = node; break; case 2: regObj['function'] = node; break; } if (++count === 3) { vm.myData.push(regObj); count = 0; obj = {}; } }); 

从本质上讲,数据的节点似乎有相同的顺序,所以我只是跟踪我接收了多less个节点,并以这种方式构build对象。 然后我把每个对象放到一个数组中以便在uigrid中使用。

例如,find()返回的数据是:

 [ { id: 1, property: foo, function: bar }, { id: 2, property: stuff, function: things } ] 

这与angular和uigrid很好。 但是随着stream,我只会得到:

 1 foo bar 2 stuff things 

这并不理想,特别是如果模型改变的话。 有没有办法发送密钥,而不只是价值? 或者也许从stream发送JSON? 就像是:

  id: 1, property: foo, function: bar id: 2, property: stuff, function: things 

谢谢!

原来我是不正确地使用双簧pipe。 我将匹配模式更改为“{id}”,一切正常。

 Oboe({ url: '/api/model/findAllStream', pattern: '{id}', start: function(stream) { // handle to the stream vm.stream = stream; vm.status = 'started'; }, done: function(parsedJSON) { vm.status = 'done'; } }).then(function() { // promise is resolved console.log('done'); }, function(error) { // handle errors console.log('error'); }, function(node) { // node received vm.gridOptions.data.push(node); });