Hassan Munir
Hassan Munir

Reputation: 449

Want to add dynamic list with dynamic data through js

There is a main file in which i want to add li in ul with dynamic value.

<ul class="selected_questions"></ul>

In my js.erb i want to show title. I have debugged it and @ques value is there but not showing in ul. Following is my code.

<% if @ques.errors.any? %>

console.log('Error');
$('#dialog-form').html('<%= escape_javascript(render('form')) %>');
<% else %>
console.log('Created');
$(".selected_questions").append('<li><span class="tab">"'[email protected]+'"</span></li>');
$('#dialog-form').dialog('close');
$('#dialog-form').remove();
<% end %>

I also have tried following way :

$('<li />', {html: @ques.title}).appendTo('ul.selected_questions')

Simple string is appended successfully but object from controller not been shown. What am i doing wrong ???

Upvotes: 0

Views: 319

Answers (1)

Preethi Mano
Preethi Mano

Reputation: 445

Try this

change this

 $("#selected_questions").append('<li><span class="tab">"'[email protected]+'"</span></li>');

to

$("#selected_questions").append('<li><span class="tab"><%= @ques.title %></span></li>');

Upvotes: 1

Related Questions