We just need to loop through the razor collection to populate the Javascript array as below: @foreach (var item in Model) { @:$(function () { @:$(“#map”).googleMap(); @:$(“#map”).addMarker({ @:coords:[@item.Latitude], @:title: `@item.City, @item.District`, @:text: `@item.Address` @:}); @:}); }
Tag: array
Split and Join in Javascript
The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method’s call. Syntax split() split(separator) split(separator, limit) Return value An Array of strings, split at each point where the separator occurs […]
Slice() method in Javascript
The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified. Syntax: slice() slice(start) slice(start, end) Parameters start Optional Zero-based index at which to start extraction. A negative index can be used, indicating […]
Splice() method in Javascript
The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. To access part of an array without modifying it, you should use the slice() method. Syntax: splice(start) splice(start, deleteCount) splice(start, deleteCount, item1) splice(start, deleteCount, item1, item2, itemN) Parameters start The index at which to […]
Pop, Push, Shift and Unshift Array Methods in JavaScript
pop(): Remove an item from the end of an array (returns the removed item) push(parameterToAdd): Add items to the end of an array (returns the new array length) shift(): Remove an item from the beginning of an array (returns the removed item) unshift(parameterToAdd): Add items to the beginning of an array (returns the new array […]
Convert comma separated string into a List in C#
string myList = “9,3,12,43,2”; List<int> intList = myList.Split(‘,’).Select(int.Parse).ToList();
Converting a List to a comma separated string in C#
List<int> list = new List<int>() {1,2,3}; string.Join<int>(“,”, list) Join has generic overloads. It is so much easier to use it in that way to convert your list to the different types.
How to find the first missing value in a series in MS SQL
Let’s say we have this values in the database: num — 1 2 4 5 6 8 9 11 To Find the first missing value, we can use this: ;WITH CteRN AS( SELECT *, RN = num – ROW_NUMBER() OVER(ORDER BY num) FROM tbl ) SELECT TOP 1 num – RN FROM CteRN WHERE RN […]
Determine If string contains more than 1 value in C#
Let’s say you have a condition like that: if ((myString.Contains(“Value1”) && (myString.Contains(“Value2”)) && (myString.Contains(“Value3”))) { … } Basically, you want to check if all of your values are contained in the string . Fortunately (with the help of LINQ), this can by translated almost literally into C#: var values = new String[] {“Value1”, “Value2”, “Value3”}; if […]
How to select distinct rows in a datatable in C#
dataTable.DefaultView.ToTable(true, “target_column”); first parameter in ToTable() is a boolean which indicates whether you want distinct rows or not. second parameter in the ToTable() is the column name based on which we have to select distinct rows. Only these columns will be in the returned datatable. If you need to get distinct based on two columns: dataTable.DefaultView.ToTable(boolean, params string[] columnNames)
Repeater Function in PHP
You need to do a while loop to pull each rowset. mysql_fetch_array() will only pull one row at a time. Consider this solution: <?php $dbhost = ‘xxxx’; $dbuser = ‘xxxx’; $dbpass = ‘xxxx’; $dbname = ‘xxxx’; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’); mysql_select_db($dbname, $conn); $result = mysql_query(“SELECT * FROM mytable”, $conn); <table> […]