簡體   English   中英

使用ECMAScript的具有相同標題的SharePoint列表項目

[英]SharePoint List items with the same titles using ECMAScript

我需要向Visual Web Part添加腳本,通過單擊按鈕,巫婆將在文本框中顯示具有相同標題的ListItems。 作為基礎,我使用了以下腳本:

<script type="text/javascript">

ExecuteOrDelayUntilScriptLoaded(MainFunction, "sp.js");

var objContext = null;
var objWeb = null    
var objList = null;
var objItem = null;

    function MainFunction() {  
        objContext = new SP.ClientContext.get_current();
        objWeb = objContext.get_web();  
        objList = objWeb.get_lists().getByTitle("Product");

        objContext.load(objList);

        objContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));  
    }  

    function onSuccess(sender, args) {
        alert('Item Count: ' + objList.get_itemCount());
    }  

    function onFail(sender, args) {  
        alert('Some error has occured.');  
    } 
 </script>

我的問題是:“是否可以通過某種方式改進此腳本來實現我的目標?”

這里是:

SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists["CustomList"];
            SPQuery qry = new SPQuery();

            qry.Query = @" <Where><Eq> <FieldRef Name='Title' /><Value Type='Text'>" + TextTitle.Text + "</Value></Eq></Where>";

            SPListItemCollection result = list.GetItems(qry);

            TextBoxCheck.Text = result.Count.ToString() + " matches has been found";  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM