【发布时间】:2014-09-16 15:31:13
【问题描述】:
我已经通过Laravel Blade tutorial。我在我的项目中使用它。但我想根据下拉列表中选择的项目添加不同的刀片模板视图。
示例:- 我有一个创建 Question.blade.php 页面。
Question.blade.php
<div class="question_type">
<?php $question_type= array('--' => '--- Select Question Type ---')
+QuestionType::lists('name', 'id') ?>
{{ Form::select('question_type', $question_type,'--' ,array('id'=>'question_type','class' => 'form-control')) }}
</div>
现在我想根据在 Question_Type 下拉列表中选择的选项添加不同类型的视图。我正在尝试用 Java Script 来做。
Java 脚本代码:-
function addQuestion()
{
var question_type=$("#question_type").val();
switch (question_type)
{
case 1:
$("#Questions").load("questions/type1.blade.php");
case 2:
$("#Questions").load("questions/type2.blade.php");
default:
$("#Questions").load("questions/default_type.blade.php");
}
}
但我收到错误 localhost/mywebsite/question/questions/type1.blade.php 404 (Not Found)
是否有任何解决方案可以根据下拉所选项目的值使用@if @else 或@switch 包含刀片视图?
我的伪代码:-
@if {{question_type.selected.val='1'}}
@include(question.type1);
@elseif {{question_type.selected.val='2'}}
@include(question.type2);
@else
@include(question.default_type);
@endif
【问题讨论】:
-
$.load("questions/type1.blade.php");需要 url(返回视图),而不是视图文件的路径 -
我可以使用 PHP 吗?
-
js不能访问blade,{{}}也不能运行js
-
有什么办法吗?我的意思是我不想在 JavaScript 页面中编写整个 HTML 代码来附加它。它不喜欢清洁剂。