读取 SPFieldChoice 选项类型的三种方法 ,第三种方法目前有问题没有解决,请高手来解决一下
2012-06-07 10:47
239 查看
目前有个技术要求,要通过三种方法读取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()" />
第一种:在服务端读取
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()" />
相关文章推荐
- win7系统右键菜单没有小工具选项的解决方法
- windows 7 没有休眠选项 解决方法
- eclipse安装maven插件及从svn检出项目时没有check out as maven project选项解决方法
- 有关修改mac地址过程中配置选项中没有“修改本地mac地址”选项的解决方法
- IntelliJ IDEA 中 右键新建时,选项没有Java class的解决方法和具体解释
- workflow没有Activity Properties,parameter editor,新建项目时的选项 的解决方法.
- 关于xcode7.2以后 Build Settings Linking 默认没有 Other Linker Flags选项的解决方法
- 解决泛泰A850L编译CM10.2(android4.3)自带相机没有1300w分辨率选项的方法
- 解决方法:Eclipse的 window-->preferences里面没有Android选项
- 为什么在存储过程中局部变量不能申明text,ntext,image类型的,高手帮我解决一下啊?(急)
- 初学OpenCV3,运行编程入门上读取并播放视频的原版程序,编译通过但是没有任何输出,已按网上博主各种方法试,还是没有结果,大家看怎么解决?
- 无法识别的属性“type”+IIS没有Asp.net配置选项的解决方法(转)
- IntelliJ IDEA 中 右键运行时没有run;新建时,选项没有Java class的解决方法和具体解释
- c# 解决读取Excel混合文本类型,数据读取失败的解决方法
- IntelliJ IDEA 中 右键运行时没有run;新建时,选项没有Java class的解决方法和具体解释
- 无法识别的属性“type”+IIS没有Asp.net配置选项的解决方法
- windows8下恶意软件导致右键菜单中没有个性化选项的解决方法
- 右击新建没有word、excel选项的解决方法
- <s:property>标签从后台读取Date类型年份为两位在jsp页面显示的解决方法