V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wework
V2EX  ›  程序员

chatgpt 写代码还真是可以

  •  
  •   wework · 44 天前 · 614 次点击
    这是一个创建于 44 天前的主题,其中的信息可能已经有所发展或是发生改变。
    今天通过 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: []
    }
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3019 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 08:17 · PVG 16:17 · LAX 01:17 · JFK 04:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.