To do list νμ΄μ§λ€μ΄μ ꡬν
json-serverλ₯Ό νμ©ν΄μ νμ΄μ§λ€μ΄μ ꡬννκ² μ΅λλ€
- json-server: https://github.com/typicode/json-server
νμ΄μ§λ€μ΄μ μ ꡬννκΈ° μν μ€μ κ°μ μ΄ 4κ°κ° νμν©λλ€
- currentPage: νμ¬ νμ΄μ§
- totalCount: μ΄ λ°μ΄ν°μ κ°―μ
- pageCount: νλ©΄μ λνλ νμ΄μ§ κ°―μ
- limit: ν νμ΄μ§ λΉ λνλΌ λ°μ΄ν°μ κ°―μ
λ°λΌμ
- currentPage: 1
- totalCount: 53 (totalCountλ μμ μ€μ )
- pageCount: 5
- limit: 5
μ΄ νμ΄μ§ κ°―μ κ³μ°νκΈ°
μ΄ λ°μ΄ν°μ κ°μλ₯Ό ν νμ΄μ§λΉ λνλΌ λ°μ΄ν°μ κ°μλ‘ λλ μ€λλ€.
μ΄ λ, μ¬λ¦Όμ νλ μ΄μ λ λ§μ§λ§ νμ΄μ§μ λ°μ΄ν°μ κ°μκ° limitμ κ°μλ³΄λ€ μμλ 보μ¬μΌνκΈ° λλ¬Έμ λλ€.
let totalPage = Math.ceil(totalCount / limit)
μλ₯Ό λ€μ΄λ³΄λ©΄, 53(μ΄ λ°μ΄ν° κ°μ)μ 5(ν νμ΄μ§ λΉ λ°μ΄ν° κ°μ)λ‘ λλλ©΄ 10νμ΄μ§κ° λμ€λλ°
λ§μ§λ§ 3κ°μ λ°μ΄ν°λ 11νμ΄μ§μ 보μ¬μΌνκΈ° λλ¬Έμ μ¬λ¦Όμ ν΄μ€λλ€.
const totalCount = 53
const limit = 5
let totalPage = Math.ceil(totalCount / limit) // 11
νμ¬ νμ΄μ§μ κ·Έλ£Ή κ³μ°νκΈ°
νμ¬ νμ΄μ§κ° λͺλ²μ§Έ κ·Έλ£Ήμ μν΄μλμ§λ₯Ό μμμΌ
νμ¬ νμ΄μ§ κ·Έλ£Ή μμ 첫λ²μ§Έ μ«μμ λ§μ§λ§ μ«μλ₯Ό ꡬν μ μμ΅λλ€.
νμ¬ νμ΄μ§ κ·Έλ£Ήμ ꡬνκΈ° μν΄μλ
νμ¬ νμ΄μ§λ₯Ό 보μ¬μ€ νμ΄μ§ κ°μλ‘ λλ μ£Όλ©΄ λ©λλ€
const currentPage = 1
const pageCount = 5
let pageGroup = Math.ceil(currentPage / pageCount) // 1
const currentPage = 7
const pageCount = 5
let pageGroup = Math.ceil(currentPage / pageCount) // 2
νμ¬ νμ΄μ§ κ·Έλ£Ήμ 첫λ²μ§Έ/λ§μ§λ§ μ«μ ꡬνκΈ°
νμ¬ νμ΄μ§ κ·Έλ£Ήμ 첫λ²μ§Έ~λ§μ§λ§ μ«μλ§νΌ νμ΄μ§λ₯Ό νλ©΄μ νμν΄μ€ μ μλ€.
κ·Έλ¦¬κ³ νμ΄μ§λ€μ΄μ
μ μ΄μ , λ€μμ ꡬνν μ μλ€
μ΄μ μ λλ₯΄λ©΄ μ΄μ κ·Έλ£ΉμΌλ‘ λκ²¨μ£Όκ³ λ€μμ λλ₯΄λ©΄ λ€μ κ·Έλ£ΉμΌλ‘ λ겨μ€λ€.
const pageGroup = 1
const pageCount = 5
const totalPage = 11
let lastNumber = pageGroup * pageCount // 5
if (lastNumber > totalPage) {
lastNumber = totalPage
}
let firstNumber = lastNumber - (pageCount - 1) // 1
const next = lastNumber + 1 // 6
const prev = firstNumber - 1 // 0
// 1~5λ§νΌ νμ΄μ§λ€μ΄μ
κ·Έλ €μ€
for (let i = firstNumber; i <= lastNumber; i++) {
html += `<button class="pageNumber" id="page_${i}">${i}</button>`
}
const pageGroup = 3
const pageCount = 5
const totalPage = 11
let lastNumber = pageGroup * pageCount // 15
if (lastNumber > totalPage) {
lastNumber = totalPage // 11
}
let firstNumber = lastNumber - (pageCount - 1) // 7
const next = lastNumber + 1 // 12
const prev = firstNumber - 1 // 6
'π©βπ€ νλ‘ νΈμλ > javascript' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Javascript][Node.js] Github actionsλ₯Ό μ΄μ©ν΄μ README μλ μ λ°μ΄νΈνκΈ° (0) | 2022.12.02 |
---|---|
[Javascript] var, let, const (0) | 2022.06.22 |
[Javascript] inputμμ 컀μ 맨 λ€λ‘ μμΉ μν€κΈ° (0) | 2022.06.03 |