Ho un allineamento di Ruby come questo nel mio controller:Dall'array Ruby all'array JS in Rails- 'quote'?
@location_list = [
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]
E sto Facendo in questo modo, a mio avviso:
location_list = "<%= @location_list.to_json %>";
Ma se faccio alert (location_list), ottengo:
[["Mushrooms",3],["Onions",1],["Olives",1],["Zucchini",1],["Pepperoni",2]]
Come posso ottenere l'oggetto corrispondente, senza quelle & quot?
L'ho provato. Il problema principale è che quando eseguo raw o html_safe vedo "Identificatore imprevisto" (nella console) quando provo ad usare quella var. Anche se vedo la fonte, posso vedere questo: var location_list = "[[" Funghi ", 3], [" Cipolle ", 1], [" Olive ", 1], [" Zucchini ", 1], [ "Pepperoni", 2]] "; console.log (location_list); - Cosa può succedere? –
@HommerSmith Come stai provando ad usarlo? Inoltre, se è effettivamente quotato in quel modo, è una stringa - non una matrice; hai provato 'as_json'? –
Sto solo provando a mostrarlo nella console ... Fondamentalmente voglio passare un array da Ruby a JS ... Se cambio l'array di ruby è come questo: @location_list = [1,3,4] - - Non capisco quell'errore È solo quando ci sono stringhe all'interno della matrice che ottengo "identificatore imprevisto" nella mia console di Chrome. –