texi rv texi rv - 1 month ago 10
AngularJS Question

using backward slashes it takes entire path

  • I am trying to pass the path of file and get the filename alone in my grid.

  • right now its working for forward slashes but its not working for backward slashes.

  • when I give whole path using backward slashes it takes entire path

  • can you guys tell me how to fix it.

  • providing my code below

working scenario test/player.txt
not working scenario test\player.txt


template: "<a onclick=\"window.open('#= FileName#', 'popup', 'width=800,height=600,scrollbars=yes,resizable=no')\">#= FileName.substring(FileName.lastIndexOf('/')+1) #</a>"

Answer Source

One solution would be to replace all the \ with / before adding it into the grid. Just like this:

      grid.dataSource.add({"FileName":$("#fname").val().replace(/\\/g,"/"),"LastName":"Last Name"});


Please note that the \ is used to escape special characters (as you did with the \"), so to get a \ you have actually to type \\. For more information look at the Special Characters block on this page: https://www.w3schools.com/js/js_strings.asp