• 读取 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" onclick="GetChoiceValue()" />

  • 相关阅读:
    会跳舞的树(只用HTML+CSS)(转)
    国内UED收录
    HDU 1078 dfs+dp
    HDU 1278
    HDU 4499
    HDU 4597
    POJ2777
    POJ1780 Code
    简单的Fleury算法模板
    POJ 2513 无向欧拉通路+字典树+并查集
  • 原文地址:https://www.cnblogs.com/Fengger/p/2539933.html
Copyright © 2020-2023  润新知