[英]Console.log shows my element as an array instead of an element
I'm doing a view where the customer is able to edit items, it comes with a filter so he/she can select between the options given.我正在做一个视图,客户可以在其中编辑项目,它带有一个过滤器,因此他/她可以在给定的选项之间进行选择。 Everytime I edit it and save it works, however, if I return to the edit section the text box is empty and even though it was saved.每次我编辑它并保存它时,但是,如果我返回到编辑部分,文本框是空的,即使它被保存了。 If i use the inspect tool, the Console shows this:如果我使用检查工具,控制台会显示:
impuestos_compra: Array [ {…} ]
If I open it, this is the information displayed:如果我打开它,这是显示的信息:
impuestos_compra: (1) […]
"$$hashKey": "object:87"
0: Object { id: 2, empresa_id: 6, nombre: "IVA", … }
length: 1
<prototype>: Array []
This is the <DIV>
label where I display this:这是我在其中显示的<DIV>
标签:
<div class="form-group col-md-6">
<label>
Impuestos de Mario
</label>
<select ng-model="articulo.impuestos_compra" name="impuestos_compra" class="form-control input-lg" required>
<option value="">Seleccione impuesto de compra</option>
<option ng-repeat="item in impuestos_compra" value="@{{ item.abreviacion }}">@{{ item.abreviacion }}</option>
</select>
</div>
In my try to iterate it, I did this code:在尝试对其进行迭代时,我执行了以下代码:
impuestos_compra = ['IVA' , 'IVAT0' ];
impuestos_compra.forEach(function(impuestos_compra) {
console.log(impuestos_compra);
});
And, finally, the controller from Laravel with the edit function looks like this:最后,来自 Laravel 的带有编辑功能的控制器如下所示:
public function edit($id)
{
$articulo = Articulo::with('sat_producto:clave,descripcion', 'sat_unidad:clave,descripcion')->findOrFail($id);
return view('panel.configuracion.articulo', [
'id' => $id,
'presentaciones' => Presentacion::select('nombre')->get()->toArray(),
'impuestos_compra' => Impuesto::select('abreviacion')->where('tipo' , 'compra')->get(),
]);
What am'I doing wrong?我究竟做错了什么? I tried ->get()->toArray()
and it works neither.我试过->get()->toArray()
并且它都->get()->toArray()
。
Thanks in advance.提前致谢。
I think the problem is in your impuestos_compra
initialization.我认为问题出在您的impuestos_compra
初始化中。 You can try pluck instead of select.您可以尝试 pluck 而不是 select。 Pluck returns the value of the column as a collection. Pluck 将列的值作为集合返回。 Try the following code.试试下面的代码。
public function edit($id)
{
$articulo = Articulo::with('sat_producto:clave,descripcion', 'sat_unidad:clave,descripcion')->findOrFail($id);
return view('panel.configuracion.articulo', [
'id' => $id,
'presentaciones' => Presentacion::select('nombre')->get()->toArray(),
'impuestos_compra' => Impuesto::where('tipo' , 'compra')->pluck('abreviacion')->toArray(),
]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.