How do I change the reservation on mobile

Asked

Viewed 35 times

0

I used jQuery-Seat-Charts to make a layout and reserve seats, the problem is that when it is on mobile I wanted otherwise.

On desktop is like this:

 map: [
          'a[,4]a[,8]a[,12]a[,16]a[,20]a[,24]a[,28]a[,32]a[,36]a[,40]a[,44]a[,48]a[,53]',
          'a[,3]a[,7]a[,11]a[,15]a[,19]a[,23]a[,27]a[,31]a[,35]a[,39]a[,43]a[,47]a[,52]',
          '____________a[,51]',
          'a[,2]a[,6]a[,10]a[,14]a[,18]a[,22]a[,26]a[,30]a[,34]a[,38]a[,42]a[,46]a[,50]',
          'a[,1]a[,5]a[,9]a[,13]a[,17]a[,21]a[,25]a[,29]a[,33]a[,37]a[,41]a[,45]a[,49]',
        ],

And on mobile I want it like this:

 map:[
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aa_aa',
          'aaaaa',
        ],

Right now it’s like this for mobile and desktop: Desktop e mobile And I want it to stay that way on mobile:

inserir a descrição da imagem aqui

  • The link you have placed does not seem to be working and the logic of what you want to do is not entirely clear. Start by explaining the logic of transformation and give more specific examples. For me it is not clear how it arrives from initial to final.

  • @Isac I updated the question and the link I hope I was more specific :)

  • confused what you want to do, but if you want to change the javascript according to mobile or not, you should test navigator.userAgent, see for example in this answer: https://stackoverflow.com/a/3540295/4730201

  • If I understand the way this plugin works, your final example is not consistent with the first, because it does not explicitly indicate each of the number of places, as it did in the first. Start by updating this part to be clear

1 answer

1


What you are trying to do is basically transpose a 2D array. The problem is that in your case it is not even a 2D array but an array of strings which adds difficulty to the problem.

In addition to this the example of output that has not play with the input, because the input has the numbers of places with a[,1], a[,2] and in the exit no longer has this discrimination just staying aa.

I place here a simplified solution that serves for what you have, but which you may have to adjust using the information you use. Still you should give an idea of how to approach the problem. The exit will be the same with the places as it has at the entrance.

const lugares = [
      'a[,4]a[,8]a[,12]a[,16]a[,20]a[,24]a[,28]a[,32]a[,36]a[,40]a[,44]a[,48]a[,53]',
      'a[,3]a[,7]a[,11]a[,15]a[,19]a[,23]a[,27]a[,31]a[,35]a[,39]a[,43]a[,47]a[,52]',
      '____________a[,51]',
      'a[,2]a[,6]a[,10]a[,14]a[,18]a[,22]a[,26]a[,30]a[,34]a[,38]a[,42]a[,46]a[,50]',
      'a[,1]a[,5]a[,9]a[,13]a[,17]a[,21]a[,25]a[,29]a[,33]a[,37]a[,41]a[,45]a[,49]',
    ];

const divisores = {'a':true , '_':true};

//colocar espaços antes de 'a' e '_' para de seguida transformar em 2D
let lug2d = lugares.map(fila => fila.split('').
  map((letra, pos) => (pos != 0 && letra in divisores) ? ' '+letra : letra).join(''));

//transformar em 2d à custa de split pelos espaços colocados previamente
lug2d = lug2d.map(fila => fila.split(' '));

//criar o array 2d final para a transposição
let lug2dTransposto = [];
for (let i = 0; i < lug2d[0].length; ++i){
  lug2dTransposto.push([]);
}

//transpor
for(let i = lug2d.length - 1; i >=0 ; --i){
    for(let j = 0; j < lug2d[i].length ; ++j){
        lug2dTransposto[j].push(lug2d[i][j]);
    }
}

//retransformar do array 2d para array de strings
let lugFinal = lug2dTransposto.map(fila => fila.join(''));
console.log(lugFinal);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.