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 :)

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

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题