YII2依赖于其他放射科医生的放射科医生

YII2依赖于其他放射科医生的放射科医生,yii2,yii2-advanced-app,yii2-basic-app,yii2-user,yii2-model,Yii2,Yii2 Advanced App,Yii2 Basic App,Yii2 User,Yii2 Model,我有两张表,如下所示 tbl\U测试: id | testname | description 待测试项目: id | itemname | description | testid 我需要为他们两个都使用一个放射科医生,这样当我为测试选择放射科医生时,只会显示所选测试中的testitem列表。这是我的密码: <?= $form->field($model, 'labtestid')->radioList( ArrayHelper::map(Labrator

我有两张表,如下所示

tbl\U测试:

id | testname | description
待测试项目:

id | itemname | description | testid
我需要为他们两个都使用一个放射科医生,这样当我为测试选择放射科医生时,只会显示所选测试中的testitem列表。这是我的密码:

<?=
$form->field($model, 'labtestid')->radioList(
        ArrayHelper::map(Labratorytest::find()->orderBy('testName')->all(), 'testid', 'testName'), [
    'onchange' => '$.post( "index.php?r=labratorytestitem/lists&id=' . '"+$(this).val(), function(data){
      $( "select#suggesttest-labtestitemid" ).html( data );
    });'
    , 'return' => true], ['id' => 'test'])->label('');
?>

我认为您的代码中有一些错误。首先,您混合了
post
get
请求。您的
onchange
事件正在触发
post
请求,但您尚未指定要发送的任何数据。然后,您的控制器期望收到
get
请求,但没有收到请求。你没有告诉yii在回显你的数据后结束,而控制器名称看起来是错误的,这是打字错误吗

无论如何,试试这段代码。我建议对代码进行一些简化,以使其更易于阅读

在您的视图文件中

<?=
//Note the url, as you asked for it, is to a controller called `laboratorytestitem`, not `testitems` as you've called the controller
$url = Url::to(['/laboratorytestitem/lists', 'id' => $model->id]);
$js = <<<JS
    $(#suggesttest-labtestid).on('change', function(){
        $.get($url, function(data){
            $( "select#suggesttest-labtestitemid" ).html( data );
        })
    });
JS
$this->registerJs($js);

$form->field($model, 'labtestid')->radioList(
        ArrayHelper::map(Labratorytest::find()->orderBy('testName')->all(), 'testid', 'testName'), ['return' => true, 'id' => 'test'])->label('');
?>

运行代码时,请检查浏览器上控制台的输出,以确保它找到了正确的url,并且发送的数据符合预期,服务器的响应符合预期。这样,您就可以指出任何问题。

我认为您的代码中犯了一些错误。首先,您混合了
post
get
请求。您的
onchange
事件正在触发
post
请求,但您尚未指定要发送的任何数据。然后,您的控制器期望收到
get
请求,但没有收到请求。你没有告诉yii在回显你的数据后结束,而控制器名称看起来是错误的,这是打字错误吗

无论如何,试试这段代码。我建议对代码进行一些简化,以使其更易于阅读

在您的视图文件中

<?=
//Note the url, as you asked for it, is to a controller called `laboratorytestitem`, not `testitems` as you've called the controller
$url = Url::to(['/laboratorytestitem/lists', 'id' => $model->id]);
$js = <<<JS
    $(#suggesttest-labtestid).on('change', function(){
        $.get($url, function(data){
            $( "select#suggesttest-labtestitemid" ).html( data );
        })
    });
JS
$this->registerJs($js);

$form->field($model, 'labtestid')->radioList(
        ArrayHelper::map(Labratorytest::find()->orderBy('testName')->all(), 'testid', 'testName'), ['return' => true, 'id' => 'test'])->label('');
?>

运行代码时,请检查浏览器上控制台的输出,以确保它找到了正确的url,并且发送的数据符合预期,服务器的响应符合预期。这样你就可以找出任何问题。

大家好,请帮帮我!大家好,请帮帮我!
<?=
//Note the url, as you asked for it, is to a controller called `laboratorytestitem`, not `testitems` as you've called the controller
$url = Url::to(['/laboratorytestitem/lists', 'id' => $model->id]);
$js = <<<JS
    $(#suggesttest-labtestid).on('change', function(){
        $.get($url, function(data){
            $( "select#suggesttest-labtestitemid" ).html( data );
        })
    });
JS
$this->registerJs($js);

$form->field($model, 'labtestid')->radioList(
        ArrayHelper::map(Labratorytest::find()->orderBy('testName')->all(), 'testid', 'testName'), ['return' => true, 'id' => 'test'])->label('');
?>
public function actionLists($id) {
    $testItems = \app\models\Labratorytestitem::find()
        ->where(['testid' => $id])
        ->all();
$count = count($testItems);
$output = '';
    if ($count > 0) {
        foreach ($testItems as $item) {
            $output .= '<input type="radio" name="' . $item->itemName . '" value="' . $item->itemid . '>';
        }
    }
    echo $output;
    Yii::$app->end();
}