2016-11-28 147 views
0

我正在为我的商店开发销售点(POS)。我正在开发一个Meteor应用程序,它将连接到POS收据打印机。但正如你所知道的,你不能简单地使用window.print()。流星科尔多瓦打印插件

我看过但没有理解Meteor有关这方面的文档,我有几个关于它的问题。 (https://guide.meteor.com/mobile.html#using-plugins

我已经安装了katzer/cordova-plugin-printer(https://github.com/katzer/cordova-plugin-printer)。并且知道这里来的问题。

1.-安装完毕后,我创建了服务器和客户端文件夹之外的文件,并插入作为

if (Meteor.isCordova) { 
 
    console.log("Printed only in mobile Cordova apps"); 
 
}

这样的语句,然后我只需添加以下行?

if (Meteor.isCordova) { 
 
document.addEventListener('deviceready', function() { 
 
    // cordova.plugins.printer is now available 
 
}, false); 
 
    }

2:如果这是正确的,难道我的服务器或Meteor.isCordova创建流星方法?来调用下面的例子。

var page = '<h1>Hello Document</h1>'; 
 

 
cordova.plugins.printer.print(page, 'Document.html');

3 .-我应该使用服务器端渲染创建

var page = '<h1>Hello Document</h1>';

一部分。

谢谢

回答

1

要回答你两点:

  1. Meteor.startup在运行时的设备或浏览器已准备好(这相当于你在做什么)。

  2. 在客户端代码中创建方法 - 将检查置于按钮单击方法中。喜欢的东西在最后的代码块,你从浏览器

if (Meteor.isCordova) { 
     Meteor.call("myPrintMethod",other-info); 
    } else { 
     alert("Sorry, I can only print from the device" 
    } 
+0

谢谢@mikkel'打印

  • 服务器端渲染将不适用({ “点击#imprimir':function(){ var id; id = FlowRouter.getParam('id'); if(Meteor.isCordova){0}document.addEventListener('deviceready',(function(){}),false); page ='

    你好文档

    '; return cordova.plugins.printer.print(page,'Document。HTML'); }); } else { return window.print(); } } });' – Orozcorp