我想訪問JavaScript中的Ruby數組。請告訴我這樣做的方法。我的數組持有一個SQL查詢的結果。訪問javascript中的紅寶石數組
@contacts = Contact.order("contacts.position ASC")
我試圖做到這一點....
for(var i=0; i< a; i++)
{
var firstnameV = "<%=Contact.order('contacts.position ASC')[i].first_name%>";
var lastnameV = "<%=Contact.order('contacts.position ASC')[i].last_name%>";
var emailV = "<%=Contact.order('contacts.position ASC')[i].email%>";
var contactV = parseInt("<%=Contact.order('contacts.position ASC')[i].contact_no%>";
var posV = parseInt("<%=Contact.order('contacts.position ASC')[i].position%>";
tx.executeSql('INSERT INTO contact_table (firstname, lastname, email, contact, pos)
VALUES (firstnameV,lastnameV, emailV, contactV, posV)');
}
只需渲染json並通過ajax訪問它 – apneadiving 2011-02-03 08:44:09
@apneadiving您能否請您展示一下步驟。我是全新的rails和ajax。 – rdp 2011-02-03 09:07:53