我正在做react-rails app.我收到了这个奇怪的错误.似乎这是反应本身的问题.这是我收到此错误的上下文:
var ChronicBox = React.createClass({
getInitialState: function(){
return {chronics: []}
},
componentWillMount: function(){
$.ajax({
// some ajax call that setsState of chronicles
});
},
render: function(){
return(
<div className="chronics">
<ChronicsList chronics={this.state.chronics.chronicsList} />
</div>
)
}
});
Run Code Online (Sandbox Code Playgroud)
和My ChronicsList看起来像:
var ChronicsList = React.createClass({
render:function(){
console.log(this.props.chronics);
var chronics = this.props.chronics.map(function(chronic){
return(
<Chronic name={chronic.name}/>
)
});
return(
<ul>
{chronics}
</ul>
)
}
});
Run Code Online (Sandbox Code Playgroud)
从日志我看到这个:
undefined
can not read property .map of undefined
Cannot read property '_currentElement' of null
Run Code Online (Sandbox Code Playgroud)
从这些我看到最初状态的时间顺序为空,因此.map不能使用.然后当ajax调用setsState时,我的ChronicBox重新渲染,而chronics包含json信息,如下所示:
{
"chronicsList": [{ …Run Code Online (Sandbox Code Playgroud) 在我的html/css应用程序中,我有一个按钮的概念,实质上是.button具有一堆适当属性的类.这是一个简化的例子:
.button {
width: 120px;
height: 30px;
line-height: 30px;
background: yellow;
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<div class="button">
<div class="button-text">
Button text
</div>
</div>Run Code Online (Sandbox Code Playgroud)
在少数地方,需要显示的文本相当长,但仍需要完全适合.由于font-stretch财产不支持,我使用transform: scale,它做我需要的 - 有点...除了上述,我有:
.button {
width: 120px;
height: 30px;
line-height: 30px;
background: yellow;
text-align: center;
}
.button-text {
line-height: 30px;
transform: scale(0.7, 1);
white-space: nowrap;
}Run Code Online (Sandbox Code Playgroud)
<div class="button">
<div class="button-text">
Very long button text
</div>
</div>Run Code Online (Sandbox Code Playgroud)
文本现在适合,但它不居中,因为在应用变换之前计算div中居中内容的位置 - 请参阅此jsfiddle中的示例:https://jsfiddle.net/1xz1g634/1/
我可以通过对其应用负左边距来"制造"它.button-text,但是这是一个黑客,并且在不同的浏览器中边距必须不同.
我怎样才能普遍地将该文本作为中心?理想情况下,不使用javascript,但是,如果其他一切都失败了,我可以使用javascript/jquery.
我一直在考虑用户身份验证,使用会话/ cookie以及会话劫持带来的安全风险所带来的问题.我知道使用安全的https://是最有效的方法,以及regenerate_session_id()和使用随机字符串进行验证(在众多其他程序中).
我的问题是:是否有可能采用放弃会话和cookie的方法,并仅使用数据库保存的变量?
我将如何设置它:
- 在用户表中有一个可以容纳IP地址的列,以及一个布尔值的列.
- 当用户"登录"时,将用户的当前IP地址设置到数据库中,并将布尔值设置为false(如果用户不想被"记住")或者设置为true(如果他们这样做).
- 在页面加载时,它使用存储在用户数据库中的IP地址检查当前IP地址.如果匹配,则认为用户有效.
- 在窗口关闭时,脚本将清除这些值,用户将被"注销".
- 如果用户想要"保持登录状态"(我知道这是一个巨大的安全风险),那么切换(布尔值)将简单地停用注销脚本,并且IP地址将保留为用户存储.
这种方法的后备是什么?它甚至可能吗?
function setup() {
var names = [];
var name = {firstname: "", lastname: ""};
name.firstname = "John";
name.lastname = "Doe";
names.push(name);
name.firstname = "Bill";
name.lastname = "Smith";
names.push(name);
return names;
}
var temp = setup();
print temp[0].firstname;
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚如何从函数返回一个对象数组.知道我哪里错了吗?
问题是存储的结果temp如下:
[
{
firstname: "Bill",
lastname: "Smith"
},
{
firstname: "Bill",
lastname: "Smith"
}
]
Run Code Online (Sandbox Code Playgroud) arrays ×1
css ×1
function ×1
html ×1
ip-address ×1
javascript ×1
object ×1
php ×1
reactjs ×1
return ×1