Проблема с получением данных из объектаJquery

Программирование на jquery
Ответить
Anonymous
 Проблема с получением данных из объекта

Сообщение Anonymous »

У меня возникли проблемы с отображением правильных значений в следующем коде. Журнал консоли верен, но когда фактическая информация добавляется на страницу, она отклоняется на 1.
Я надеюсь отобразить следующее:

Код: Выделить всё

Name    James   person ID   1
first location  $35
fee amount calculated
fee3    a million in spacecash
Name    Jordan  person ID   2
second location $40
fee amount calculated
Вот код:

Код: Выделить всё

$(document).ready(function() {
for (person of personInformation) {
const personTable = document.createElement("table");
personTable.innerHTML = "Nameperson ID";
personTable.setAttribute("id", "table");

const newRow = document.createElement("tr");
newRow.setAttribute("class", "personRow");
const first_name = document.createElement("th");
const person_id = document.createElement("th");

console.log('person', person)

person_id.textContent = person.person_id;
first_name.textContent = person.first_name;
console.log(first_name);
$("th#personName").after(first_name);
$("th#personId").after(person_id);
personTable.appendChild(newRow);
for (fees of person.fees) {
const feeRow = document.createElement("tr");
const fee = document.createElement("td");
const amount = document.createElement("td");
fee.textContent = fees.name;
amount.textContent = fees.amount;
console.log("fee", fee);
feeRow.appendChild(fee);
feeRow.appendChild(amount);
personTable.appendChild(feeRow);
}
console.log(person_id);
console.log(first_name);
const persons = document.getElementById('test');
persons.appendChild(personTable);
}
console.log(personInformation);
$('#personSearch').on('input', function() {
let value = $(this).val().toLowerCase();
let searchVal1 = $('.personRow').find('td').text();
let searchVal2 = $('.personRow').text();
$('form').filter(function() {

console.log('searchVal1', searchVal1);
console.log('searchVal2', searchVal2);
$(this).toggle($(this).text()
.toLowerCase().indexOf(value) > 0);
});
});
});

Код: Выделить всё















const personInformation = [{
"person_id": 1,
"first_name": "James",
"fees": [{
"name": "first location",
"amount": "$35"
},
{
"name": "fee",
"amount": "amount calculated"
},
{
"name": "fee3",
"amount": "a million in spacecash"
}
]
},
{
"person_id": 2,
"first_name": "Jordan",
"fees": [{
"name": "second location",
"amount": "$40"
},
{
"name": "fee",
"amount": "amount calculated"
}
]
}
];


Спасибо за любые предложения!

Подробнее здесь: https://stackoverflow.com/questions/790 ... rom-object
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»