我有一个程序,人们可以对视频发表评论。评论来自队列状态。管理员可以进入管理部分并将评论标记为已批准或已删除。他们希望能够在按下上一个或下一个按钮时自动转到队列中标记的下一个项目,以及他们是否批准或删除评论。我不太了解jQuery或JavaScript,知道是否可以使用它们,或者如何通过后面的代码(这是在C#.NET中)来实现它。任何帮助将不胜感激:
Status and value:
In queue = 0
Approved = 1
Removed = 2
这是代码隐藏。状态更改工作,我唯一不能做的就是让它转到队列中标记的下一条记录。前两个事件是空白的,因为我不知道如何填充它们,但简单地说,所有需要做的就是转到队列中标记的下一个记录。
如果您需要更多代码,请告诉我们......
protected void previous_clicked(object sender, EventArgs e)
{
}
protected void next_clicked(object sender, EventArgs e)
{
}
protected void approve_clicked(object sender, EventArgs e)
{
currentMessage = new videomessage(Request["id"].ToString());
status.SelectedValue = "1";
currentMessage.status = "1";
currentMessage.Save();
}
protected void remove_clicked(object sender, EventArgs e)
{
currentMessage = new videomessage(Request["id"].ToString());
status.SelectedValue = "2";
currentMessage.status = "2";
currentMessage.Save();
}
答案 0 :(得分:2)
听起来更像是对我的建筑挑战。
我建议使用Queue。这是遵循first-in, first-out(FIFO)方法的集合类型。您将对象放入队列并以相同的顺序将其退出。从队列中接收的对象将自动从队列中删除,因此您可以确保不会两次处理相同的元素。
您描述的工作流程将按以下简单步骤运行:
next button
时,您请求第一个对象out of the queue。Next
再次从上面的第1项开始。<强> [编辑] 强>
哎呀,我意识到我的Queue
方法不允许导航回以前的项目。
在这种情况下,我建议使用简单的List
集合。可以通过列表中基于0的位置访问此列表。这样可以轻松实现向前/向后导航。
对于我的示例代码,请记住,有很多我无法了解您的环境,所以我的代码在这里做了很多假设。
您需要在某个地方存储包含待批准邮件的集合:
private IList<videomessage> _messagesToApprove = new List<videomessage>();
您还需要一些跟踪集合中当前位置的变量:
// Store the index of the current message
// Initial value depends on your environment. :-)
private int _currentIndex = 0;
首先,您需要一个新消息添加到该集合的起点,例如订阅某个事件。每当消息到达时,通过调用如下方法将其添加到集合中:
// I made this method up because I do not know where your messages really come from.
// => ADJUST TO YOUR NEEDS.
private void onNewMessageArriving(string messageId)
{
videomessage arrivingMessage = new videomessage(messageId);
_messagesToApprove.Add(arrivingMessage);
}
您可以通过递增/递减位置索引轻松实现导航:
private void previous_Click(object sender, EventArgs e)
{
// Check that we do not go back further than the beginning of the list
if ((_currentIndex - 1) >= 0)
{
_currentIndex--;
this.currentMessage = this._messagesToApprove[_currentIndex];
}
else
{
// Do nothing if the position would be invalid
return;
}
}
private void next_Click(object sender, EventArgs e)
{
// Check if we have new messages to approve in our list.
if ((_currentIndex + 1) < _messagesToApprove.Count)
{
_currentIndex++;
currentMessage = _messagesToApprove[_currentIndex];
}
else
{
// Do nothing if the position would be invalid
return;
}
}
private void approve_Click(object sender, EventArgs e)
{
// Sorry, I don't know where exactly this comes from, needs to be adjusted to your environment
status.SelectedValue = "1";
this.currentMessage.status = "1";
this.currentMessage.Save();
// If you want to remove items that have been checked by the admin, delete it from the approval list.
// Otherwise remove this line :-)
this._messagesToApprove.RemoveAt(_currentIndex);
}
private void remove_Click(object sender, EventArgs e)
{
// Sorry, I don't know where exactly this comes from, needs to be adjusted to your environment
status.SelectedValue = "2";
this.currentMessage.status = "2";
this.currentMessage.Save();
// If you want to remove items that have been checked by the admin, delete it from the approval list.
// Otherwise remove this line :-)
this._messagesToApprove.RemoveAt(_currentIndex);
}
答案 1 :(得分:0)
在会话或viewstate中保存当前评论的id
,将其恢复到下一个或上一个按钮点击并显示相应的内容:
Session["id"] = 2;
int id = (int) Session["id"];