首页 > 解决方案 > array.push 添加整数作为字符串

问题描述

嗨,我将 laravel 与 vuejs 和 javascript 代码一起使用,这是我的 vuejs 代码

for(i = 0;i<response['data'].length;i++)
{
    this.edited_lines.push(
        {
            id:response['data'][i]['id'], // this is integer
            cost_center_id:response['data'][i]['cost_center_id'], // this is integer
            credit:response['data'][i]['note'], // this is string
        }
    );
}

直到现在一切都很好..但是在我的刀片中我做了这个代码

<tr v-for='line , id in edited_lines'>
    <td>
        @php   $cost_center_id = "{{line['cost_center_id']}}"; @endphp
         {{gettype($cost_center_id)}}  // this always resturn string not integer 
    </td>
</tr>

并且因为如果我在刀片中执行此操作,它总是返回字符串而不是整数,我会报错

{{$cost_center_id * 1}} // if i put this code in my blade i gat error below
A non-numeric value encountered

我试着这样做..

cost_center_id:1,

并在这里得到同样的错误任何帮助谢谢..

标签: javascriptphplaravel

解决方案


推荐阅读