1

我在 SharePoint 2010 中有一个包含一些列的列表。都是默认类型。所以我有
“单行文本”
“多行文本”
“日期和时间”
“选择”
“数字”
“货币”
“个人或组”

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

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

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 没有多大帮助。

SUBQUESTION:如果您能告诉我如何将 PostBack 到可以使用客户端对象模型的 .cs 文件,我会跳过使用 EcmaScript。我发现了一些东西,但没有工作/理解。

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

谢谢。

4

1 回答 1

4

好的,我从用户Vardhaman Deshpande那里得到了Sharepoint.Stackoverflow.com的解决方案。这行得通。

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

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();

来自: http: //www.learningsharepoint.com/2011/07/06/how-to-get-various-item-fields-using-client-object-model-ecmascript-sharepoint-2010/

更新:以下代码正在运行和测试。

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!');
}
于 2012-01-26T12:10:25.123 回答