<select ng-model="ad.Categorie"
ng-options="obj.id as obj.name for obj in categories"
ng-change="getSubcategories()"
class="form-control"
ng-required="true"
name="categorie">
<option value="">-- --</option>
</select>
當我提出讓NG選項數組索引,而不是ad.Categorie價值,我解決了隱藏的輸入angularjs越來越NG選項OBJ ID而不是價值
<input type="hidden" name="categorie" value="@{{ad.Categorie}}" />
但似乎不對任何解決方案理念?
var categories = [{"id":1,"name":"cat1"},{"id":2,"name":"cat2"}];
從數據庫讀取數據。我想要類別ID爲fk
public function store(Request $request)
{
$ad = new Ad;
$ad->categorie_id= $request->categorie;
$ad->subcategorie_id= $request->subcategorie;
$ad->type_id= $request->type;
$ad->location_id= $request->location;
$ad->title= $request->title;
$ad->description= $request->description;
$ad->price= $request->price;
$ad->phone= $request->phone;
$ad->code= $request->code;
//$ad->img = $request->file('img');
//$files = $request->file('img');
$ad->save();
return redirect('/');
}
是這個數組$ request-> categorie這就是爲什麼我得到索引?
可以提供的JSON'categories'。你也可能在你的選擇中出現拼寫錯誤(在'name'屬性後沒有關閉''') – haxxxton
var categories = [{「id」:1,「name」:「name1」},{「id」:2 ,「名稱」:「名稱2」}]從數據庫中讀取是的「在代碼中是正確的 –
'ng-options =」obj.name for obj in categories「'does not work? – imudin07