sharepoint list项目单击事件和值更改

时间:2017-10-21 02:23:19

标签: sharepoint

所以我的目标是允许用户点击列表中的项目,它会自动更改项目的值。大多数情况下,我希望用户能够轻松地将项目标记为正在阅读。此列表将每周更新,因此它将允许用户更容易地了解新内容。我已经设置了视图,因此用户只能在个人视图中看到自己的数据。

我在网上看过,但我没有好运。这是我到目前为止所做的。

<script src="https://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script><script type="text/javascript">
$(document).ready(function() {
$(".ms-listviewtable > tbody > tr").click(function(){  //only works before ajax runs
    setTimeout( function() {
    //alert("Hello! I am an alert box!!");
    var ctx = SP.ClientContext.get_current("https://...");
    var items = SP.ListOperation.Selection.getSelectedItems(ctx);
    var clientContext = new SP.ClientContext();
    var oList = clientContext.get_web().get_lists().getByTitle('Ticket');
    this.oListItem = oList.getItemById(items[0].id);
    this.oListItem.set_item('read','yes');
    this.oListItem.update(); 
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
    }, 200);  //had to be put in place to give time for the list to be selected
}); 
}); 

这些是我的问题。

  1. 我第一次单击它告诉的项目是SP.ListOperation.Selection.getSelectedItems为null。但是,如果我点击相同的项目,它将给我ID号码。然后如果我第三次点击它会再次告诉我它的空值。
  2. 它不会改变vaule,但是在我点击两次后它确实给了我正确的ID号。
  3. EDIT,

    见下面的评论

1 个答案:

答案 0 :(得分:0)

使用此代码:

$("table.ms-listviewtable").on("mouseup", "tr.ms-itmhover", function() {
        //your code
});