douxing9567 2015-07-25 23:36
浏览 37
已采纳

使用PHP和JavaScript更新DOM中的用户参与者列表,如GitHub问题

In my Project Management App I want to show an HTML list of users with there Thumbnail avatar image for all users who have edited a Task record.

I am calling this list the participant list just like GitHub does for there Issues. GItHUb shows a lisrt of user thumbnails sorted by date to show the most recent active user who participatedon an Issue in a GitHub repo. I want to reproduce this functionality on my Task records.

So when a user edits a Task record they will be added to a participant list sorted by most recent activity. It will show there thumbnail image. If a user is already in the list and they make another edit, they will not be added 2x to the list. Instead they will be moved to position 1 in the sort order of thumbnails if they are not already at that position!

enter image description here

This flow below explains how it would function in more detail...

if(user is not in participant list){

    // Add user to DB for this Task record participant list with there Datetime and UserID of the update.
    // Then add there image to the participant list in front of the others at position number 1

}elseif(user is already in participant list){

    if(if user is in DOM HTML participant list at position number 1){

        // update DB participant list with Datetime for this user but do not update the DOM HTML

    }elseif( if user is not in position number 1){

        // update DB with Datetime for user in participant list and then also update the participant 
        // list DOM HTML to remove the users image and then re-add it at position number 1

    }

}

I will be processing the edits the user made in the backend with PHP so at that same time would be ideal for me to update there last activity DateTime and add them to the participant list in the DB.

I would then like to handle the functionality of adding, re-ordering, etc of the thumbnail list in the DOM with JavaScript.

So perhaps the PHP could return a JSON string of data to indicate if the user need to be re-ordered in the DOM list or added if they do not even exist yet!

If anyone has any ideas on how to implement the JavaScript side of this, I am open to all input please


More flow theory:

  • My PHP JSON could return a flag indicating if the user avatar is already in the previous list or not. If not it will know it needs to add the user as he doesn't exist at all yet.
  • The PHP flag would also indicate in the case that use had already been in previous participant list and needs it's sort order updated. This would mean removing previous thumbnail image in the old sort order location in the DOM HTML and re-adding back into position 1
  • 1 idea is to simply have the PHP return the full HTML of the whole list with all users in correct sort order each time but this would mean it would be updating even when the user doesn't need to change position or be added. It would also mean more data being transferred however this is the simple route and I might just do it if I can't get a better solution from this question.
  • Reconsidering. My PHP could also send back a flag indicating that no new sort order change or new user addition exist so do not make any DOM updates. It would then only send back a new userlist in the event that a new user is added to list or else previous user needs to update sort order.
  • 写回答

1条回答 默认 最新

  • duanbi3151 2015-07-26 00:17
    关注

    Good detail on your thought process. My approach would be to combine your third and fourth bullet points under "flow theory". Wiping out the whole list and dropping in the new one will save on expensive DOM operations/logic. Having PHP tell you whether the order changed would prevent any unnecessary DOM work.

    Best practice for this type of insert is to create a document fragment for the whole list; you can also use a templating engine, but that would be overkill if you don't need it for anything else.

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

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题