How to do it

1. In the JavaScript block, define the function getCount() to return the length of the Contact array:

function getCount() {

var retval = this.data.Contact.length;

return ((retval>0)? retval:"No contact numbers are available");

The function returns a message No contact numbers are available if the length of the Contact array is 0 for any Employee record.

In the document.ready() function of the jQuery script block, define the Employee array:

var EmployeeData = [

{ EmpID: "I53434", Name: "Richard Tan", Email: "[email protected] com", Contact: ["+65 24242444","+65 9842422442","+6 5 673222222"]}, { EmpID: "I53435", Name: "Thomas Lee", Email: "[email protected] com", Contact: ["+65 8664664","+65 9331313311"]}, { EmpID: "I53436", Name: "Joseph Yeo", Email: "[email protected] com", Contact: []},

{ EmpID: "I53437", Name: "Jasmine D'Souza", Email: "[email protected] someemail.com", Contact: ["+65 4225252","+65 623242422", "+65 96424242"]}

3. Apply the array to the template employeeTemplate and append to the contentTble table on the form:

$("#employeeTemplate").tmpl(EmployeeData). appendTo("#contentTble");

Thus, the complete jQuery solution is as follows:

<script language="javascript" type="text/javascript"> $(document).ready(function() { var EmployeeData = [

{ EmpID: "I53434", Name: "Richard Tan", Email: "[email protected] com", Contact: ["+65 24242444","+65 9842422442","+6 5 673222222"]}, { EmpID: "I53435", Name: "Thomas Lee", Email: "[email protected]", Contact: ["+65 8664664","+65 9331313311"]},

{ EmpID: "I53436", Name: "Joseph Yeo", Email: "[email protected]", Contact: []},

{ EmpID: "I53437", Name: "Jasmine D'Souza", Email: "[email protected]

com", Contact: ["+65 4225252","+65 623242422", "+65 96424242"]} ];

$("#employeeTemplate").tmpl(EmployeeData).

function getCount() {

var retval = this.data.Contact.length;

return ((retval>0)? retval:"No contact numbers are available");

0 0

Post a comment