2017-03-09 111 views
-1

是否可以在file.Js的列上執行函數?例如:Suppliers是我的專欄名稱。JSLink在列上執行函數

我想執行一個功能

var lookupSample = lookupSample || {}; 

lookupSample.CustomizeFieldRendering = function() { 
// Intialize the variables for overrides objects 
var overrideCtx = { 
    Templates: { 
     Fields: { 
      'Suppliers': { 
       'NewForm': lookupSample.singleLookupValue 
      }, 
     } 
    } 
}; 
overrideCtx.Templates.OnPostRender = PostRenderJs; 


// Register the override of the field 
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx); 
} 

lookupSample.singleLookupValue = function(ctx) { 
var output = []; 
var field = ctx.CurrentFieldSchema.Choices; 
output.push('<div class="ui-widget"> <select id="combobox">'); 
// Check if field contains data 
if (field.length > 0) { 
    for (i = 0; i < field.length; i++) { 
     output.push('<option id="'); 
     output.push(field[i].LookupId); 
     output.push('">'); 
     output.push(field[i].LookupValue); 
     output.push('</option>'); 
    } 
    output.push('</select></div>'); 
} 
// Push the value to the array 
return output.join(''); 
} 

function PostRenderJs (ctx){ 
    alert('Hello World'); 
} 

lookupSample.CustomizeFieldRendering(); 

此代碼做我想做什麼,但它開3(因爲我有3列在我的名單,如果我有4列,即彈出4次,等)警報與相同的消息。

而且我只想彈出此消息1次(根據我的列Suppliers)。

喜歡的東西

function PostRenderJs (ctx){ 
    if(ctx.columnname=="Suppliers"){ 
    alert('Hello World'); 
    } 
}; 

因此,這將彈出的Hello World只有1次。如果你想執行一段特定的域代碼而已,你可以直接寫代碼爲特定領域

回答

0

請參考下面的代碼片段。

var options = { 
     Templates: { 
     Fields: { 
      'Field1_Internal_Name': { 
       View: /* function or string */, 
       EditForm: /* function or string */, 
       DisplayForm: /* function or string */, 
       NewForm: /* function or string */ 
      }, 
     } 
     }, 
    }; 

在參照上面的代碼中,

  1. 與字段的內部名稱取代 「Field1_Internal_Name

  2. 指定無論您是書面方式您的視圖代碼,EditForm,DisplayForm ,NewForm

  3. 編寫代碼。

參考:https://www.codeproject.com/Articles/620110/SharePoint-Client-Side-Rendering-List-Views

+0

我編輯我的職務。 我只需要知道如何執行一個函數,當columnname =列 –