jquery - How to convert a string with an HTML code into a working HTML code (in Ruby or Javascript)? -



jquery - How to convert a string with an HTML code into a working HTML code (in Ruby or Javascript)? -

i putting next code ruby array:

@data << "=> <div><a href='/company/#{d.name}'>see profile</a></div>"

i've tried this:

@data << "=> <div><a href='/company/#{d.name}'>see profile</a></div>".html_safe

but didn't help me.

i passing @data json (@data.to_json), in js, need have label see profile link, not text. tried

label1 = variable_with_the_string_from_above.html();

but didn't help me out too... in js variable see profile still plain text (<div><a href='/company/#{d.name}'>see profile</a></div>), not html link.

how that?

thank guys

in javascript:

var htmlarray = ["<div><a href='/company/#{d.name}'>see profile</a></div>"];

to inject html:

document.write(htmlarray[0]);

if passing {d.name} variable, seek angularjs.

create controller , scope ->

app.controller('mainctrl', ['$scope', function ($scope) { $scope.dname = dname(); etc. }]);

and in html or js:

var htmlarray = ["<div><a href='/company/{{dname}}'>see profile</a></div>"];

make sure array within range of controller scope!

<div ng-controller="mainctrl"> ... </div>

an easier way utilize angularjs routing:

sampleapp.config(['$routeprovider', function($routeprovider) { $routeprovider. when('/companyone', { templateurl: 'templates/c1.html', controller: 'c1' }). when('/companytwo', { templateurl: 'templates/c2.html', controller: 'c2' }). otherwise({ redirectto: '/default' }); }]);

javascript jquery html ruby

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -