我习惯用这种方式在PHP中接近它,所以我想知道是否有可能在Javascript中做到这一点.这是我试过的:
$("#company-details").html(function () {
var find = ['%title%', '%description%', '%photo%', '%website%', '%branch%', '%refnr%'];
var replace = [value.title, value.description, value.photo, value.website, value.branch, value.refnr];
return $(this).html().replace(find, replace);
});
Run Code Online (Sandbox Code Playgroud)
但是,只要我向任何数组添加超过1个值,它就不再起作用了.
我似乎无法重置默认状态;我怎么做?我试过这个,但它所做的只是添加state到状态并将其称为未定义。
const initialState = {
name: null,
coins: 0,
image: null,
};
export default function reducer(state = initialState, action = {}) {
switch (action.type) {
case types.ADD_GROUP_COINS:
return {
...state,
coins: state.coins + action.coins
};
case types.DELETE_GROUP:
return {
state: undefined
};
default:
return state;
}
}
Run Code Online (Sandbox Code Playgroud) 我想在数组中获取数组的值,但我无法使其工作.这是我试过的.
for($i=2;$i<=$row_count;$i++){
$auto_part = 'auto_part'.$i;
$auto_parts['part'][] = $_POST[$auto_part];
$description = 'auto_description'.$i;
$auto_parts['description'][] = $_POST[$description];
}
foreach($auto_parts as $part){
echo $part['part'];
echo $part['description'];
}
Run Code Online (Sandbox Code Playgroud)
for循环是正确的,数组也按照我想要的方式构建,我检查了一下.但是如何在一个foreach中获得$ part ['part']和$ part ['description']的两个数组?
我试图在一个for循环中插入一个Stringbuilder,但它崩溃了.这是我的代码
StringBuilder sb = new StringBuilder("This is a text");
for(int i = 0;i < sb.length();i++){
if(sb.charAt(i) == 't'){
sb.insert(i, 't');
}
}
Run Code Online (Sandbox Code Playgroud)
这样做的目的是使每个't'加倍.
当我尝试parseInt()时,它说:
_this2.state.grade.parseInt不是函数
码:
this.state = {grade: "1"}
let grade = this.state.grade.parseInt()
Run Code Online (Sandbox Code Playgroud)
这个功能在React Native中不起作用吗?如果是这样我怎么能把它转换成int?
我需要使用md5()而不是bcrypt()用于存储密码。但是当我这样做时:
protected function create(array $data)
{
return Account::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => md5($data['password']),
'datetoday' => Carbon::now(),
'lastip' => request()->ip(),
'confirmation' => bcrypt($data['password']),
]);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试登录时,提示凭据错误。
我将我的项目设置为Less in Angular,以便在我的CSS中使用变量的好处.但问题是我必须在每个组件中定义那些不能使其有效的变量.有没有办法将变量设置为globaly?
所以我想摆脱这个:
在我的组件中:
@pink-color: #FC9DB5; // I want to get this from a single
// file which I import on each component
header {
background-color: @pink-color;
height: 100px;
}
Run Code Online (Sandbox Code Playgroud)