我有一个选择框,具有两个字段组合值作为单个选项
例如:name1(name1_code),name2(name2_code)并从ajax调用响应中填充此值。我有一个用于提交表单和编辑页面的表单。如果我有$id
,我想在选择框中填充值。我尝试过
js code
$.each(data, function(key, value) { //populate value
$('#project_name').append($("<option></option>")
.text(value).attr("value",key));
});
Php
if(isset($id))
{
$types=DB::table('sow_mapping as m')->leftJoin('sow as s','m.sow_id','=','s.id')->leftJoin('project as p','p.id','=','m.project_id')->where('p.code','=',$asset_request->project_code)->pluck('s.number','s.code')->all();
$sow_code=db::table('sow')->where('code',$asset_request->sow)->value('number');
echo Form::select('sow_name',
[''=>'Select']+$types,$asset_request->sow.'('.$sow_code.')',['class'=>'selectpicker default','id'=>'sow_name']);
}
print_r($types) output as
Array ( [SOW_1395] => WJT - SOW 07 )
I want to print as `SOW_1395(WJT - SOW 07)`
是否可以打印为SOW_1395(WJT - SOW 07)
答案 0 :(得分:0)
您可以将键附加值
$.each(data, function(key, value) { //populate value
$('#project_name').append($("<option></option>")
.text(key+'('+value+')').attr("value",key));
});