dongyu6276 2014-01-03 14:51 采纳率: 0%
浏览 39
已采纳

尝试使用函数创建可排序列表[关闭]

Hi guys I'm trying to create a list of stocks for an automobile dealer to display their stock, I've been searching over the web for useful plugins but can't decide which direction to go for, javascript or php? Which plugin is popular for sorting list? Any recommendation is welcome.

Here are some basic requirements:

  • Won't be a lot of items since it's for one dealer.
  • Need functions like: Sort by Price (Highest to Lowest), Sort by KMs (Lowest to Highest), etc.
  • Each list item will have many attributes, for a car it may have large amount of categorised description, images, and video etc, so it might not be a good idea retrieving from database? Just my idea.

Under my circumstances, I don't know which one is the best option. I am a web designer, so I understand a little PHP and JS, but not enough for this project. Any help is appreciated!

  • 写回答

1条回答 默认 最新

  • dqcqcqwq38860 2014-01-03 15:37
    关注

    My recommendation is to use JavaScript and i will explain. Javascript is purely client side language which handles no data transfer and payload on server. Javascript is not an object oriented language (PHP as well), which means you can insert entire different objects in any array / list cell. Now, for your need : You can build a simple array in javascript and apply easy made functions to return sorted arrays. For Example, a function that will sort your array by KM:

    function sortKilometers ()
    {
    if (a.Kilometers > b.Kilometers) return 1;
    if (a.Kilometers === b.Kilometers) return 0;
    if (b.Kilometers > a.Kilometers) return -1;
    }
    

    function like this will just return a sorted array easily. Pay attention, my code here can be incorrect, im too tired to simulate it, but most sort functions in javascript works this way. PHP is working almost the same but javascripts counts as a lighter and more easy-to-use language.

    hope that it was helpful :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路