我有一个非常简单的node.js noob问题.如何将变量传递给导出的路径函数?
路由文件
exports.gettop = function(n, req, res) {
console.log(n);
res.send(200);
};
Run Code Online (Sandbox Code Playgroud)
服务器文件
app.get('/api/v1/top100', routes.gettop(100));
Run Code Online (Sandbox Code Playgroud)
错误:.get()需要回调函数但得到[对象未定义]
我意识到"在Heroku上运行PhantomJS"是一个相关但略有不同的问题,因为我正在尝试使用节点应用程序.
我在为节点应用程序部署casperJS(基于phantomJS)脚本时遇到问题.我已经尝试通过将PhantomJS 64位二进制文件放在我的应用程序/bin目录中来部署到Heroku ,但是当我尝试运行PhantomJS时出现以下错误:
phantomjs: error while loading shared libraries: libQtWebKit.so.4: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
从我读过的内容可以通过安装QtWebKit库来解决,但是Heroku没有安装它.是否有其他我可以使用的托管服务提供商可以使用或在Heroku上安装此软件包的方法?
相关代码:
app.get('/', function(request, response) {
var sys = require('sys')
var exec = require('child_process').exec;
var child;
//works but gives error while loading shared library libqtwebkit.so.4
child = exec("phantomjs --version | tr -d '\n'", function(error, stdout, stderr) {
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr + '\n');
response.header('Content-Type', 'application/json');
response.send('_testcb(stdout:' + stdout + '\nstderr:' + …Run Code Online (Sandbox Code Playgroud) 我正在尝试克隆另一个开发人员拥有的私有存储库.我没有与这位开发人员直接沟通.他们给我发了一个hisusername-id_rsa.pub文件和一个他们的用户名-priv.key.ppk文件.我理解ppk文件特定于Putty ssh客户端.有人能为我提供如何克隆他们的回购的步骤吗?我已经使用我自己的帐户配置了git,我想我必须将他们的ssh密钥添加到我的ssh/config文件或其他东西,但我有点像ssh菜鸟.
git clone git@github.com:theirusername/pro.git
Cloning into 'pro'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)
编辑:我能够访问github存储库并将自己添加为协作者.即便这样做,我也做不到
git clone git@github.com:theirusername/pro.git
Run Code Online (Sandbox Code Playgroud)
然而
git clone https://github.com/theirusername/pro.git
Run Code Online (Sandbox Code Playgroud)
做得好.
我正在尝试返回与特定用户标识相关联的优惠券列表并填充_merchant引用.
此查询正确填充_merchant引用.如果我可以添加:
coupon.users.contains(myuserid)到我的查询将获得我需要的东西
db.couponModel.find().populate('_merchant').exec(function(err, coupons) {
res.send(coupons);
});
Run Code Online (Sandbox Code Playgroud)
或者此查询找到我需要的正确优惠券.如果我可以添加:
填充(_merchant)到我的查询,也将得到我需要的.
db.userModel.findById(req.params.id).populate('coupons').exec(function(err, user) {
res.send(user.coupons)
});
Run Code Online (Sandbox Code Playgroud)
架构
var userSchema = new Schema({
email: { type: String, required: true , unique: true },
coupons: [{ type: Schema.ObjectId, ref: 'Coupon' }]
});
var couponSchema = new Schema({
_merchant: { type: Schema.ObjectId, ref: 'Merchant', required: true },
couponid: { type: Number, required: true, unique: true },
users: [{ type: Schema.ObjectId, ref: 'User' }]
});
var merchantSchema = new Schema({
name: { type: String, required: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在用户点击它时切换按钮图像.如果可能的话,我更喜欢使用angularjs而不是jquery.现在我有一个可以在点击时切换图像的工作版本,唯一的问题是它会在点击时更改所有图像.如何缩小范围或传递img元素的src属性?
<div ng-repeat="merchant in merchants">
<div class="followrow">
<a ng-click="toggleImage()"><img id="followbutton" ng-src="{{followBtnImgUrl}}" /></a>
</div>
</div>
app.controller('FollowCtrl', function CouponCtrl($scope) {
$scope.followBtnImgUrl = '/img1'
$scope.toggleImage = function () {
if ($scope.followBtnImgUrl === '/img1.jpg') {
$scope.followBtnImgUrl = baseUrl + '/img2.jpg';
} else {
$scope.followBtnImgUrl = 'img1.jpg';
}
}
});
Run Code Online (Sandbox Code Playgroud)
我可以将img src属性传递给toggleImage(this.img.src)或类似的函数吗?
我试图在Linux Mint 12上编译RemotePad Server,我在make期间收到以下错误:
gcc -lXtst -lX11 -lm -o remotepad remotepad.o ucs2keysym.o
remotepad.o: In function `handleKeyEvent':
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:369: undefined reference to `XKeysymToKeycode'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:371: undefined reference to `XTestFakeKeyEvent'
remotepad.o: In function `simulateKeyWithUnichar':
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:379: undefined reference to `XKeysymToKeycode'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:399: undefined reference to `XTestFakeKeyEvent'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:404: undefined reference to `XTestFakeKeyEvent'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:403: undefined reference to `XTestFakeKeyEvent'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:401: undefined reference to `XTestFakeKeyEvent'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:389: undefined reference to `XKeysymToKeycode'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:394: undefined reference to `XKeysymToKeycode'
/home/joe/Downloads/RemotePad Server/X11/remotepad.c:398: undefined reference to `XTestFakeKeyEvent' …Run Code Online (Sandbox Code Playgroud) 这是对我的查询的极大简化,但基本上我有一系列公共表表达式,它们相互构建,我想将它们转换为视图。问题是当我尝试使用视图时它非常慢,但当我运行查询时非常快。
CREATE VIEW user_view AS
WITH cte AS(
SELECT first,middle,last FROM user
),
cte2 AS(
SELECT *,first + middle AS first_middle FROM cte
),
cte3 AS(
SELECT *,first_middle + last AS full_name FROM cte2
)
SELECT * from cte3;
Run Code Online (Sandbox Code Playgroud)
快速查询
WITH cte AS(
SELECT first,middle,last FROM user WHERE user_id = 5
),
cte2 AS(
SELECT *,first + middle AS first_middle FROM cte
),
cte3 AS(
SELECT *,first_middle + last AS full_name FROM cte2
)
SELECT * from cte3;
Run Code Online (Sandbox Code Playgroud)
使用视图慢查询
SELECT …Run Code Online (Sandbox Code Playgroud)