V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
wework
V2EX  ›  程序员

chatgpt 写代码还真是可以

  •  
  •   wework · Mar 13, 2024 · 1402 views
    This topic created in 774 days ago, the information mentioned may be changed or developed.
    今天通过 chatgpt 写了一个静态可分页的数据列表,感觉还是挺满意的

    以下是 JavaScript 代码片段,完整页面效果可以看看 shuai.la

    async function getItemsFromFile() {
    try {
    const response = await fetch('file.txt'); // Update the path to your local text file
    const content = await response.text();
    const items = content.split('\n').map(item => item.trim());
    state.itemsList = items.filter(Boolean); // Filter out empty lines
    state.totalItems = state.itemsList.length; // Calculate total items
    state.totalPage = Math.ceil(state.totalItems / state.perPage); // Update total page count
    list.update();
    } catch (error) {
    console.error('Error loading file:', error);
    }
    }

    const html = {
    get(element) {
    return document.querySelector(element);
    }
    }

    const perPage = 10; // Number of items per page
    const state = {
    page: 1,
    perPage,
    totalItems: 0, // Initialize total items
    totalPage: 0, // Initialize total page count
    maxVisibleButtons: 5,
    itemsList: []
    }
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5366 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 03:51 · PVG 11:51 · LAX 20:51 · JFK 23:51
    ♥ Do have faith in what you're doing.