我正在尝试使用laravel在if statemenet中运行javascript函数但是在尝试执行此操作时收到以下错误:
BlogViewHolder(View itemView) {
super(itemView);
mView = itemView;
textView_title = (TextView) itemView.findViewById(R.id.title);
textView_decription = (TextView) itemView.findViewById(R.id.description);
textView_address =(TextView) itemView.findViewById(R.id.address);
textView_phone =(TextView) itemView.findViewById(phone);
textView_Pickup =(TextView) itemView.findViewById(pickup);
textView_Confirm =(TextView) itemView.findViewById(confirm);
bconfirm = (Button) itemView.findViewById(R.id.bcomfirm);
bpickup = (Button) itemView.findViewById(R.id.bpickup);
bpickup.setOnClickListener(this);
bconfirm.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v.getId() == bpickup.getId()) {
// set your actions
}
//here you can use else, if the first one didn't get call
//then the second one will be
if(v.getId() == bconfirm.getId()){
// set your actions
}
}
代码:
Parse error: syntax error, unexpected ':', expecting '(' (View: C:\rcms_w\resources\views\frontend\home.blade.php)
答案 0 :(得分:1)
您使用此结构:
@if (Auth::user()->roleplay->health_points >= 100)
setHealth(1);
@elseif
setHealth(0.{{ Auth::user()->roleplay->health_points }});
@endif
被解析为
<?php if (Auth::user()->roleplay->health_points >= 100) : ?>
setHealth(1);
<?php elseif: ?>
setHealth(0.{{ Auth::user()->roleplay->health_points }});
<?php endif; ?>
elseif部分需要另一个语句(比较某些东西或期望一个布尔值)。
如果您将@elseif
更改为@else
,则应该有效。
您的新脚本将是:
<script type="text/javascript">
@if (Auth::user()->roleplay->health_points >= 100)
setHealth(1);
@else
setHealth(0.{{ Auth::user()->roleplay->health_points }});
@endif
@if (Auth::user()->roleplay->energy_points >= 100)
setEnergy(1, {{ Auth::user()->roleplay->energy_points }});
@else
setEnergy(0.{{ Auth::user()->roleplay->energy_points }}, {{ Auth::user()->roleplay->energy_points }});
@endif
@if (Auth::user()->roleplay->hygiene_points >= 100)
setHygiene(1, {{ Auth::user()->roleplay->hygiene_points }});
@else
setHygiene(0.{{ Auth::user()->roleplay->hygiene_points }}, {{ Auth::user()->roleplay->hygiene_points }});
@endif
@if (Auth::user()->roleplay->hunger_points >= 100)
setHunger(1, {{ Auth::user()->roleplay->hunger_points }});
@else
setHunger(0.{{ Auth::user()->roleplay->hunger_points }}, {{ Auth::user()->roleplay->hunger_points }});
@endif
</script>