How to Check Rating Settings is enabled or not by Javascript in SharePoint 2010?

微笑、不失礼 提交于 2019-12-10 12:12:52

问题


I have created custom Ribbon Button and I want to check Rating Settings is enable or not. If Rating Settings is Enable then Enable Ribbon Button, else Disable Ribbon Button.

This is code to get current List, but I don't see any function to check Rating Settings:

   var clientContext = new SP.ClientContext();
   var oWebsite = clientContext.get_web();
   var collList = oWebsite.get_lists();

   var listId = SP.ListOperation.Selection.getSelectedList();
   var sdlist = oWebsite.get_lists().getById(listId);

   clientContext.load(sdlist);

   function CheckRatingSettings(){
       var fields = sdlist.get_fields();
       //What next to check Ratting Setting, I can't find any function to get that
   }

回答1:


I dont think you can query that from the client API. Your best bet should be to implement a WCF service that checks that on the server and then query that Service through javascript.

Check CKS developer tools, they have among other goodies a template for visual studio to create WCF services on Sharepoint.

Another option is to check if the field "AverageRating" exists on the list, this field is added to the list when you enable ratings. Bear in mind that the field might exist but the ratings may be disabled though.

This is not tested (and assuming your code is getting the right listid, something along the lines of this:

var fields = slList.get_fields();
clientContext.load(fields );


function CheckRatingSettings(fields){
       for (var i = 0; i < fields.length; i++) {
           if (fields[i].internalName == "AverageRating") {
               return true;
           }
        }
        return false;
}


来源:https://stackoverflow.com/questions/14598301/how-to-check-rating-settings-is-enabled-or-not-by-javascript-in-sharepoint-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!