diff --git a/suanfa.js b/suanfa.js new file mode 100644 index 0000000..dd031a9 --- /dev/null +++ b/suanfa.js @@ -0,0 +1,25 @@ +Page({ + data: { + students: [], // 存储学生信息的数组 + }, + + // 从后端获取学生数据并排序 + loadStudents: function() { + const that = this; + wx.request({ + url: 'https://wx.fzu.edu.cn/info/1010/2092.htm', // 后端API地址 + method: 'GET', + success: function(res) { + const studentsData = res.data; // 后端返回按JSON格式组织好的数据 + const students = studentsData.map(student => new Student(student.name, student.id, student.points)); + // 按积分从小到大排序 + that.setData({ + students: students.sort((a, b) => a.points - b.points) + }); + }, + fail: function(err) { + console.error('Failed to load students:', err); + } + }); + }, +}) \ No newline at end of file