未捕获的ReferenceError:$未定义,jQuery和sharepoint列表

时间:2017-12-13 12:15:40

标签: jquery sharepoint

我已在SharePoint列表的editform上添加此脚本以获取级联列。我在下面的脚本中收到此错误:

CascadeDropdowns.js:4未捕获的ReferenceError:$未在CascadeDropdowns.js中定义:4(匿名)@ CascadeDropdowns.js:4

  / Sub Category List GUID 
var listGUID = "F69CA26B-82D2-4F66-93DA-18A877DBD404"; 
var arrSubCatObj = new Array(); 
$(document).ready(function(){  //HERE IT COMPLAINS ON THIS LINE
         PopulateArray(listGUID)         
        // Binding Change Event to cateogry drop down 
        $("select[id*='Category'][title='Category']").change(function(){ 
                CascadeSubCategory(this.value); 
        }); 
        CascadeSubCategory($("select[id*='Category'][title='Category']").val()); 
}); 
function CascadeSubCategory(selectedCategory){ 
         $('select[id*="SubCategory"][title="Sub Category"]').find("option:gt(0)").remove(); // First option will be (None) 
         if(arrSubCatObj.length > 0){ 
                 for(var i=0; i < arrSubCatObj.length; i++){ 
                         if(arrSubCatObj[i].CategoryId == selectedCategory){ 
                                 $('select[id*="SubCategory"][title="Sub Category"]').append("<option value='" + arrSubCatObj[i].ID + "'>" + arrSubCatObj[i].Title +"</option>");                                 
                         } 
                 } 
         } 
} 
function PopulateArray(listId) { 
    // getting list items from the offices list and storing to array. 
    //[0] Office ID, [1] Office Title, [2] Country ID 
    try { 
        //REST Query to get the display form url 
        jQuery.ajax( 
                { 
                    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/Lists(guid'" + listId + "')/items?$select=ID,Title,CategoryId&$top=1000", 
                    type: "GET", 
                    async: false,                     
                    headers: { "Accept": "application/json;odata=verbose" }, 
                    success: function (data, textStatus, xhr) { 
                        // checking if the data is returned from SharePoint or not. 
                        if (data.d.results.length > 0) { 
                            var resColl = data.d.results;                             
                            for (var i = 0; i < resColl.length; i++) { 
                                    var itemObj = new Object(); 
                                itemObj.ID = resColl[i].Id; 
                                itemObj.Title = resColl[i].Title; 
                                itemObj.CategoryId = resColl[i].CategoryId; 
                                // checking if object is not inserted in the array. 
                                arrSubCatObj.push(itemObj);                                     
                            } 
                        } 
                    }, 
                    error: function (data, textStatus, xhr) { 
                        console.error("Error while getting items from sub category list"); 
                    } 
                }); 
    } 
    catch (ex) { 
        consol.error(ex); 
    } 
} 

1 个答案:

答案 0 :(得分:0)

您缺少jQuery库文件,请在使用jQuery之前添加jQuery库文件。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

您可以根据您的要求添加任何版本的jQuery。

希望这会对你有所帮助。