读取 SPFieldChoice 选项类型的三种方法 ,第三种方法目前有问题没有解决,请高手来解决一下...

目前有个技术要求,要通过三种方法读取Choice的值,因为不同的要求及页面会用到不同的读取情况,目前第三种通过JS读取有的问题,请会的兄弟给点提示,下面将列表三种方法

第一种:在服务端读取

           using (SPSite site = new SPSite("http://moss:888"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPList list=web.Lists["Custom"];
                    SPField field = list.Fields.GetField("选项类型");
                    SPFieldChoice choice = list.Fields.GetField(field.InternalName) as SPFieldChoice;
                    foreach (string c in choice.Choices)
                    {
                        Console.WriteLine(c);
                    }
                }
            }

 

第二种:通过.net托管代码读取

        static ClientContext _clientContext;
        static Web _web;
        static List _list;
        static ListItem _listItem;
        static ListItemCollection _listItemCollection;
        static CamlQuery _query;
        static FieldLookupValue _lookupValule;
        static Field _field;
        static FieldChoice _fieldChose;

       static void putChoice()
        {
            _clientContext = new ClientContext("http://moss:888");
            _list = _clientContext.Web.Lists.GetByTitle("Custom");
            _fieldChose = _clientContext.CastTo < FieldChoice > (_list.Fields.GetByInternalNameOrTitle("选项类型"));
            _clientContext.Load(_fieldChose);
            _clientContext.ExecuteQuery();
            foreach (string choice in _fieldChose.Choices)
            {
                Console.WriteLine(choice);
            }
        }

第三种:通过ECMAJS客户端对象模型读取,程序目前可以执行成功,就是得不到Choice里面的值,请会的兄弟帮个忙

<script language="javascript" type="text/javascript">    

var context = null;    

var web = null;    

var query = null;

var list = null;

var listItem = null;    

var field=null;

    function GetChoiceValue() {        

          context = new SP.ClientContext.get_current();        

          web = context.get_web();        

          list = web.get_lists().getByTitle("Custom");        

         field = context.castTo(list.get_fields().getByInternalNameOrTitle("选项类型"), SP.FieldChoice) ;       

         context.load(field);        

         context.executeQueryAsync(Function.createDelegate(this, this.ReadChoiceSuccess), Function.createDelegate(this, this.ReadChoiceFailure));    

}

    function ReadChoiceSuccess(sender, args) {        

                alert(field.get_internalName);        //程序可以执行到这里面

                var fieldChoice = context.CastTo < SP.FieldChoice > (list.get_fields[field.get_internalName]);        

                alert(fieldChoice.DefaultValue);         //在这里面弹出未定义

                alert(fieldChoice.Choices);       //在这里面弹出未定义

                 alert(fieldChoice);    //在这里面弹出未定义

     }

    function ReadChoiceFailure(sender, args) {        

       alert("f")    

    }

</script>

<input id="btnChoice" type="button" value="button" οnclick="GetChoiceValue()" />

转载于:https://www.cnblogs.com/Fengger/archive/2012/06/07/2539933.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值