我可以跟meteor.js一起玩吗?刚刚发现了与请求相结合的cheerio.我可以用流星使用这些,还是有类似的东西?
你有一个工作的例子吗?
解决方法
当然!很难想象什么流星不能做!首先,您需要处理远程http请求的东西.在你的流星目录中终端运行流星添加http添加Meteor.Http包,还有npm安装cheerio(看看
another SO question on how to install npm modules,看看在哪里安装外部npm模块.
这是一个例子,可能会帮助你一点,它刮了current time.
服务器js
require = __meteor_bootstrap__.require; //to use npm require must be exposed. var cheerio = require('cheerio'); Meteor.methods({ getTime: function () { result = Meteor.http.get("http://www.timeanddate.com/worldclock/city.html?n=136"); $= cheerio.load(result.content); CurrentTime = $('#ct').html(); return CurrentTime; } });
客户端脚本:
Meteor.call("getTime",function(error,result) { alert("The current time is " + result); });
我希望这是有帮助的.在Cheerio中还有其他节点框架,如node.io
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。