如何检查评级设置是否由SharePoint 2010中的Javascript启用? [英] How to Check Rating Settings is enabled or not by Javascript in SharePoint 2010?

查看:123
本文介绍了如何检查评级设置是否由SharePoint 2010中的Javascript启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了自定义功能区按钮,我想检查评级设置是否启用。
如果评级设置为启用,则启用功能区按钮,否则禁用功能区按钮。

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.

这是获取当前List的代码,但我看不到任何功能检查评级设置:

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
   }


推荐答案

我不认为您可以从客户端API查询。你最好的选择应该是实现一个WCF服务,在服务器上检查它,然后通过javascript查询该服务。

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.

检查 CKS开发者工具,他们还有一个模板,供Visual Studio在Sharepoint上创建WCF服务。

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

另一个选项是检查列表中是否存在AverageRating字段,当您启用评级时,此字段将添加到列表中。请记住,该字段可能存在,但可能会禁用评级。

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.

这未经过测试(假设您的代码正在获得正确的listid,这个:

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;
}

这篇关于如何检查评级设置是否由SharePoint 2010中的Javascript启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆