2017-12-13 12 views
1

カスケード列を取得するために、このスクリプトを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

SharepointマスターページにJqueryライブラリを追加していませんでした。 –

答えて

0

あなたが欠落していますjQueryライブラリファイル、jQueryを使用する前にjQueryライブラリファイルを追加してください。

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

要件に応じて、任意のバージョンのjQueryを追加できます。

希望すると、これが役立ちます。

関連する問題