我正在使用Kartik DepDrop小部件来下拉选项。我已成功展示了这些选项。
但是我的firebug控制台出现了这样的错误
TypeError: invalid 'in' operand obj
这是我的代码:
<?php
<div class="pib-data-form">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($model, 'transaction_type')->dropDownList(PibTransactionType::getOptions(), ['id' => 'parent_id']); ?>
<?=
$form->field($model, 'doc_type')->widget(DepDrop::classname(), [
'type' => DepDrop::TYPE_SELECT2,
'options' => ['id' => 'first_child_id'],
'pluginOptions' => [
'depends' => ['parent_id'],
'placeholder' => 'Select...',
'url' => Url::to(['pib-data/document-type'])
]
]);
?>
<?php
echo FileInput::widget([
'name' => 'file_uploads',
'language' => 'id',
'options' => [
'accept' => 'doc/*', 'file/*',
'multiple' => true,
'enableLabel' => true,
],
'pluginOptions' => [
'allowedFileExtensions' => ['xls', 'xlsx'],
'uploadUrl' => Url::to(['/pib/pib-data/create']),
]
]);
?>
<?php ActiveForm::end(); ?>
</div>
<?php
$this->registerJS("
$('#w1').on('fileuploaded', function(event, data, previewId, index) {
var response = data.response;
$(location).attr('href', response.url);
}
);", View::POS_END);
public function actionDocumentType() {
$out = [];
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$parent_id = $parents[0];
$out = PibDocumentType::getOptionsbyTransactionType($parent_id);
echo Json::encode(['output' => $out, 'selected' => '']);
return;
}
}
echo Json::encode(['output' => '', 'selected' => '']);
}
TransactionType.php
public static function getOptions(){
$data= static::find()->all();
$value=(count($data)==0)? [''=>'']: \yii\helpers\ArrayHelper::map($data, 'id','name');
return $value;
}
DocumentType.php
public static function getOptionsbyTransactionType($parent_id) {
$data = static::find()->where(['transaction_type_id'=>$parent_id])->select(['id','name'])->asArray()->all();
$value = (count($data) == 0) ? ['' => ''] : $data;
return $value;
}
错误是什么意思,我该如何解决?