0
如何填充JSON數據下拉列表YII2 DROPDOWNLIST從JSON鏈接
這是JSON鏈接:http://localhost/data
這個JSON格式:
[{"inst_id":"1","inst_code":"001","inst_name":"HARVARD"},{"inst_id":"2","inst_code":"002","inst_name":"UCLA"}]
這一觀點:
<?= $form->field($model, 'institusi')->dropDownList(); ?>
「inst_id」的下拉值和「inst_name」的文本
我的代碼,但它不是主動形式
$url = 'http://localhost/data';
$content = file_get_contents($url);
$json = json_decode($content, true);
$inst=array();
echo "<select>";
foreach($json as $item) {
echo "<option value='".$item['inst_id']."'>".$item['inst_name']."</option>";
}
echo "</select>";
所以如何將JSON數據填充到的ActiveForm DROPDOWNLIST
非常感謝。它工作,你拯救了我的生命 –