У меня есть функция JavaScript в моем дереве активов. Он принимает данные от пользователя, а затем фильтрует таблицу данных по этим данным. Однако я не могу заставить его работать в моем файле index.html.erb из моего конвейера asset / javascript. Я могу поместить функцию в теги скрипта на странице index.html.erb, и она будет работать. Я также могу поместить alert ("test") в мой файл javascript, и он будет работать в index.html.erb. Может кто-нибудь взглянуть и сказать, что мне не хватает?
// # Place all the behaviors and hooks related to the matching controller here.
$('document').ready(function(){
var stateInput, stateFilter, table, tr, td, i;
stateInput = document.getElementById("stateInput");
stateFilter = stateInput.value.toUpperCase();
table = document.getElementById("myTable");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
function stateSearch() {
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(stateFilter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
});
Вот мой index.html.erb. Я включил только тег ввода, потому что я предполагаю, что это все, что вам нужно.
<input id="stateInput" type="textbox" placeholder="State ID ex. IN" onkeyup="stateSearch()">