本文介绍了如何使用EcmaScript读取列类型SPUser,DateTime,Currency?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SharePoint 2010中有一些列有一些列。所有都是默认类型。所以我有

单行文本

多行文本

日期和时间

选择

数字

货币

人或团体

I have a list in SharePoint 2010 with some columns. All are default types. So I have
"Single line of text"
"Multiple line of text"
"Date and Time"
"Choice"
"Number"
"Currency"
"Person or Group"

我的目标是有一个自定义功能区选项卡或组,我可以在此列表上执行某些操作。作为起点,我在Visual Studio解决方案中创建了一个空元素,并在Elements.xml中放入了我的按钮。这项工作到目前为止。我也想出了如何回复按下按钮做出反应。此回发引用JavaScript文件。

My aim is to have a custom ribbon tab or group where I can perform some action on this list. As a starting point I created an Empty Element in my Visual Studio solution and put inside Elements.xml my buttons. This works so far. I also figured out how to do a postback to react on pressed button. This postback refers to a JavaScript file.

在执行某些操作之前,我首先尝试读取给定内容并使用 alert('first field:'+ field1)。在第一个被调用的函数中我有

Before performing some action I tried first to read the given contents and return them using alert('first field: ' + field1). In first called function I have

function calledPostbackFunction(string button) {
    var context = SP.ClientContext.get_current();
    this.site = context.get_site();
    this.web = context.get_web();
    context.load(this.site);
    context.load(this.web);
    context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceded(button), Function.createDelegate(this, this.onQueryFailed));

如何从列出的列类型中获取内容?我记得我能够读取单个文本行和选择,但其余的都崩溃了。所以我想我必须转换它但是怎么样?IntelliSense没有多大帮助。

How can I get the content from listed column types? I remember that I was able to read single text line and choice, but the rest crashed. So I guess I have to convert it any way. But how? IntelliSense doesn't helps a lot.

SUBQUESTION:如果你能告诉我怎么做toPostBack到.cs文件,我会跳过使用EcmaScript我可以使用客户端对象模型。我找到了一些东西,但没有工作/理解。

SUBQUESTION: I would skip using EcmaScript if you can tell me how to doPostBack to a .cs file where I can use Client Object Model. I found something but didn't work/ understand.

是的,虽然这很容易,但事实并非如此。至少因为我只知道C#,没有EcmaScript。

Yes, I though this will be easy, but it was not. At least because I only know C# a bit, no EcmaScript.

谢谢。

推荐答案

好的,我得到了一个解决方案。这是有效的。

Okay, I got a solution Sharepoint.Stackoverflow.com from user Vardhaman Deshpande. This works.

以下是如何获取每种类型字段的值:

Here is How to get the value of each type of field:

Title – SP.ListItem.get_item(‘Title‘);

ID – SP.ListItem.get_id();

Url -SP.ListItem.get_item(‘urlfieldname‘).get_url()

Description – SP.ListItem.get_item(‘descriptionfieldname‘).get_description();

Current Version – SP.ListItem.get_item("_UIVersionString");

Lookup field – SP.ListItem.get_item(‘LookupFieldName’).get_lookupValue();

Choice Field – SP.ListItem.get_item(‘ChoiceFieldName‘);

Created Date – SP.ListItem.get_item("Created");

Modified Date – SP.ListItem.get_item("Modified"); -> case sensitive does not work with ‘modified’

Created By – SP.ListItem.get_item("Author").get_lookupValue());

Modified by – SP.ListItem.get_item("Editor").get_lookupValue());

File  – SP.ListItem.get_file();

File Versions -  File.get_versions();.

Content Type – SP.ListItem.get_contentType();

Parent List – SP.ListItem.get_parentList();

来自:

更新:以下代码正在运行并经过测试。

UPDATE: The following code is working and tested.

var item;
function getItemById(itemId){

    var clientContext = new SP.ClientContext.get_current();

    var web = clientContext.get_web();

    var list = web.get_lists().getByTitle('myList');

    item = list.getItemById(itemId);

    clientContext.load(item);

    clientContext.executeQueryAsync(onSuccess, onFailure);
}
function onSuccess(){

    alert(item.get_item("My User column").get_lookupValue());
}
function onFailure(){

    alert('Failure!');
}

这篇关于如何使用EcmaScript读取列类型SPUser,DateTime,Currency?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 13:02