将Vuejs $索引传递给Laravel Session数组

时间:2016-06-20 10:51:20

标签: php arrays laravel session

我创建了一个表单,其中一些输入会根据select输入中的值自动添加到表单中。防爆。 select有值3,插入3个输入,然后如果select得到值1,则最后两个输入被删除并且只保留一个输入。我用vuejs构建了这个过程。

此表单是多页表单的一部分,其数据存储在会话中,因此用户可以前后移动,并且插入的数据必须填写在适当的位置。

来自那些自动创建的输入的数据被保存到会话数组(Session :: put(“stop_airport”))并获得单个值,我必须调用类似Session :: get(“stop_airport.0”)的内容)。

因此...

如何将$ index变量从vuejs循环“v-for”传递到laravel会话数组变量Session :: get(“stop_airport.0”),将$(零)替换为$ index?

或者有另一种方法可以做到这一点?

查看

<div class="form-group{{$errors->has('stop_airport[0]') ? ' has-error' : ''}}" v-for="stop in stops" v-if="main.stops > '0'">
    <div class="col-md-6">
         <label class="control-form">Aeroporto de Escala</label>
         <input type="text" name="stop_airport[]" :placeholder="($index+1) +'ª Escala'" class="form-control airport-input" v-model="stop.airport" value="{{Session::get('stop_airport.0')}}">
         @if ($errors->has('stop_airport[0]'))
             <span class="help-block">
                   <strong>{{ $errors->first('stop_airport[0]') }}</strong>
             </span>
         @endif
    </div>
</div>

Vuejs

new Vue({
        el:'#flight-details',
        data:{
            main:{
                stops:''
            },
            stops:[],
            oldStops:''
        },
        methods: {
            updateStops: function (event) {
                // diffrence between current and old stops values
                var dif = this.main.stops - this.oldStops;
                // if negative
                if(dif < 0){
                    dif *= -1;
                    var lgt = this.stops.length - 1;
                    var index = 0;
                    for(var i=0;i<dif;i++){
                        index = lgt - i;
                        this.stops.splice(index, 1);
                    }
                // if positive
                }else if(dif > 0){
                    for(var i=0;i<dif;i++){
                        this.stops.push({
                            airport:""
                        });
                    }
                }
                // save current stops value
                this.oldStops = this.main.stops;
            },
        },
        ready: function(){
            this.updateStops();
        }
    });

0 个答案:

没有答案