Как получить идентификатор и v-текст для выбора vuejs - PullRequest
0 голосов
/ 31 января 2020

как я могу получить идентификатор и, в свою очередь, значение v-текста, чтобы сохранить его в таблице

Я хочу сохранить id таблицы malla_curricular в поле idMalla и значение полей pAcademicoInicio cicloLectivoInicio в поле periodoLectivoMallaOrigen таблицы estudio_reingreso

введите описание изображения здесь

<Label>Seleccione el periodo de la malla</Label>
 <select v-model="idMalla" class="form-control col-md-12">
  <option v-for="malla in arrayPeriodo" :key="malla.id" :value="malla.id" v-text="malla.pAcademicoInicio + ' - ' + malla.cicloLectivoInicio">

 </option>

Здесь используется метод vue, где я не знаю, как получить значения для отправки их в другую таблицу

EventSubir(){
let me = this;
axios.post('/estudioreingresomat/registrar',{     
    'id': this.id,    
    'idMalla': this.idMalla,
    'periodoLectivoMallaOrigen': this.periodoLectivoMallaOrigen,
    'periodoLectivoMallRediseñada': this.periodoLectivoMallRediseñada,
}).then(function (response) {
    console.log('EXITO!!');    
}).catch(function (error) {
    console.log('error al ingresar el estudio!!');
    console.log(error);
});
},


public function store(Request $request)    {
   if (!$request->ajax()) return redirect('/');
   try{
        DB::beginTransaction();
        $estudioReingreso = new EstudioReingreso();
        $estudioReingreso->idMalla = $request->idMalla;
        $estudioReingreso->periodoLectivoMallaOrigen = $request->periodoLectivoMallaOrigen; 
        $estudioReingreso->periodoLectivoMallRediseñada = $request->periodoLectivoMallRediseñada; 
        $estudioReingreso->save();
        session(['estudioReingreso' => $estudioReingreso->id]); 

        DB::commit();

    } catch (Exception $e){
    echo('se tosteo lpm');
    DB::rollBack();
}
}

1 Ответ

1 голос
/ 31 января 2020

(я предполагаю, что вы уже извлекли данные для arrayPeriodo)

Если вы так структурировали свои данные, вы можете получить доступ к объекту malla_selected, который будет содержать то, что вы говорите :value в вашем теге option.

шаблон:

<Label>Seleccione el periodo de la malla</Label>
<select v-model="selected_malla" class="form-control col-md-12"> <!-- changed idMalla to selected_malla, then in the option - the :value becomes the object itself -->
    <option
        v-for="malla in arrayPeriodo"
        :key="malla.id"
        :value="malla"
        v-text="malla.pAcademicoInicio + ' - ' + malla.cicloLectivoInicio">
    </option>

vue компонент:

export default {
    data(){
        return {
            malla_selected: null
            arrayPeriodo: [
                {
                    id: 1,
                    idMalla: 2,
                    pAcademicoInicio: 'foo',
                    cicloLectivoInicio: 'bar',
                }
            ]
        }
    }
    methods:{
        EventSubir(){
            axios.post('/estudioreingresomat/registrar',{
                'id': malla_selected.id,
                'idMalla': malla_selected.idMalla,
                'periodoLectivoMallaOrigen': malla_selected.periodoLectivoMallaOrigen,
                'periodoLectivoMallRediseñada': malla_selected.periodoLectivoMallRediseñada,
            }).then(function (response) {
                console.log('EXITO!!');
            }).catch(function (error) {
                console.log('error al ingresar el estudio!!');
                console.log(error);
            });
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...