我正在使用以下attach语句在数据透视表中创建一行.
$music = Music::find(1);
$music->users()->attach(1);
Run Code Online (Sandbox Code Playgroud)
这在数据透视表中插入一行但是,它没有更新时间戳.时间戳仍为0000-00-00 00:00:00
有没有办法更新数据透视表中的时间戳.?
提前致谢,
我是新来的本地人.如果用户点击文本,我编写了以下代码来调用函数.
var login = React.createClass({
openPopup: function(){
console.log("function called");
},
render: function(){
return (
<View onClick={this.openPopup}>
<Text>
Login
</Text>
</View>
);
}
});
Run Code Online (Sandbox Code Playgroud)
上面的代码有什么问题吗?如果我单击登录文本,我在控制台中没有收到任何反馈.
编辑 这个问题是特定于原生的反应.与Stack Overflow中的任何其他问题不重复.
我正在尝试promise
使用该fetch
函数更新我收到的状态.
componentDidMount(){
fetch(url).then((responseText) => {
var response = responseText.json();
response.then(function(response){
this.setState(response);
});
});
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误setState
不是函数
然后,我试图bind(this)
传递this
如下的值.
componentDidMount(){
fetch(url).then((responseText) => {
var response = responseText.json();
response.then(function(response){
this.setState(response);
});
}).bind(this);
}
Run Code Online (Sandbox Code Playgroud)
它现在也没有用.同样的错误.
我在React Native中使用了少量用户首选项AsyncStorage
.现在,我需要从后台服务中获取这些偏好.我无法AsyncStorage
从Java层访问.有办法吗?
在iOS中,我们可以导入RCTAsyncLocalStorage.h
和调用_getValueForKey
.但是,我无法找到在Android中执行此操作的方法.
我正在使用 fetch API 来调用 React Native 应用程序中的服务器查询。then
但是,我的应用程序在收到服务器的响应后需要 50 秒才能调用函数。我是否犯了任何错误,或者 Promise 运行速度是否非常慢?
fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: bodyContent
}.then((responseText) => {
console.log(responseText);
responseText.json().then(function(response){
console.log(response);
});
});
Run Code Online (Sandbox Code Playgroud)
response
50 秒后打印在日志中responseText
更新:刚刚发现承诺responseText.json()
只有在我再次点击屏幕后才会执行。这个问题很奇怪。
如果当前 url 和弹出 url 位于同一域中,我可以使用以下代码检测弹出窗口中的用户单击事件:
var myWindow = window.open("abc.html","MsgWindow", "width=500","height=600");
$(myWindow).on('click', 'a', function() {alert('a')});
Run Code Online (Sandbox Code Playgroud)
但是,是否可以从外部 url 检测用户活动,如下所示?
var myWindow = window.open("http://google.com","MsgWindow", "width=500","height=600");
$(myWindow).on('click', 'a', function() {alert('a')});
Run Code Online (Sandbox Code Playgroud)
第二个片段对我不起作用。我怎样才能让它发挥作用?
我正在尝试使用蓝牙配对设备。有时配对工作正常。但是,有时createBond()
函数返回false。如何找到失败的原因?
if(!device.createBond()){
// want to find the reason for the failure
}
Run Code Online (Sandbox Code Playgroud) 我有这样的程序.
?#include<stdio.h>
#include<stdlib.h>
int main(int i) { /* i will start from value 1 */
if(i<10)
printf("\n%d",main(++i)); /* printing the values until i becomes 9 */
}
output :
5
2
2
2
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释输出是怎么来的?每次迭代都返回main(++ i).如果我删除printf函数中的\n,它也会产生输出5111.提前致谢.