$ resource非常棒,提供了处理Web服务的非常方便的方法.如果必须在不同的URL上执行GET和POST,该怎么办?
例如,GET URL是,http://localhost/pleaseGethere/:id
而POST URL http://localhost/pleasePosthere没有任何参数
我想使用Twitter应用程序从我的网络应用程序发送推文,而不是在安装推特客户端时使用推特按钮.
如果我在安装了Twitter应用程序的iPhone或Mac上,则在将Web应用程序重定向到"twitter://"URL时会打开此应用程序.(见http://handleopenurl.com/scheme/twitter)
但是,如果我只想在未安装Twitter应用程序的地方显示Twitter按钮,我该如何检查?假设我有这个代码.twitter_app_installed()应该如何?有没有办法检查是否window.location="twitter://...";不起作用?
<div class="twitter-button"><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://google.com" data-text="Hello World">Tweet</a></div>
<div class="twitter-app-button"><a href="twitter://post?message=Hello%20World%20http://google.com">Tweet</a></div>
<script>
function twitter_app_installed() { /* check if window.location="twitter://"; works */}
$(document).ready(function() {
if (twitter_app_installed()) $('.twitter-app-button').show();
else $('.twitter-button').show();
});
</script>
Run Code Online (Sandbox Code Playgroud)
另外:有没有正确的方法将URL添加到twitter://方案?
假设我有这个模型:
module.exports = {
attributes: {
title: {
type: 'string',
required: true
},
content: {
type: 'string',
required: true
},
createdBy: {
type: 'string',
required: true
}
}
}
Run Code Online (Sandbox Code Playgroud)
我需要将当前用户ID设置为模型的createdBy属性.我以为我可以使用beforeValidate生命周期回调来做到这一点,但我无法访问存储当前用户的请求对象.有没有办法访问它,或者我应该以其他方式解决这个问题?
我试过这个没有成功:
beforeValidate: function (values, next) {
var req = this.req; // this is undefined
values.createdBy = req.user.id;
next();
}
Run Code Online (Sandbox Code Playgroud)