Bind an even to dynamically appended html in ionic 3 - html

I am developing an app with the help of ionic 3
in the application i am generating dynamic html from .ts file and appending in HTML . Now i want to bind and click event to html
After user done an click event i want to refresh the content present in the dynamically generated html
please help to solve this
enter code here
my .ts file
with the below code i am generating html and appending to html
outputHtml = '<div id="rpl_crt"><div class="sys_ot"><h6 class="itm_nme">My Cart</h6>';
var innerHTML = '';
let amount = 0;
let savings = 0;
for (let dt in data) {
amount += data[cart].vv.value;
savings += data[cart].aa.value;
innerHTML += '<div class="cartlist">'
innerHTML += '<div class="row ">'
innerHTML += '<div col-3 class="itemimg">'
let img_url=data[cart].product.images ? ConfigurationPage.commonURL+data[dt].aa.images[1].url:'assets/img/place_holder.png'
innerHTML += '<img src="'+img_url+'" >'
innerHTML += '</div>'
innerHTML += '<div col-9>'
innerHTML += '<h6>' + data[dt].aa.name + '</h6>'
innerHTML += '</div>'
innerHTML += '</div>'
innerHTML +='<div class="btn_qnty row">'
innerHTML += '<div col-5>'
innerHTML += '<div class="row">'
innerHTML += '<div col-3 click="abc(dt)"><span class="circle">-</span></div>'
innerHTML += '<div text-center col-6 >'+data[dt].q+'</div>'
innerHTML += '<div col-3 (click)="xyz(dt)"><span class="circle " >+</span></div>'///I want an click event here to do some action
//
innerHTML += '</div>'
innerHTML += '</div>'
innerHTML += '<div col-7>'
innerHTML += '<div class="prd_dtl">'
innerHTML += '<div class="proctprice">'
if (data[dt].ss.value != 0) {
innerHTML += '<span class="orgin_prc">' + this.currency.transform((parseFloat(data[dt].tp.value) + parseFloat(data[dt].ss.value)), 'INR') + '</span>'
}
innerHTML += '<span class="dsc_prc">' + this.currency.transform(data[dt].tp.value, 'INR') + '</span>'
innerHTML += '</div>'
if (data[cart].savings.value != 0) {
innerHTML += '<p class="save_prc">' + this.currency.transform(data[dt].ss.value, 'INR') + '</p>'
}
innerHTML += '</div>'
innerHTML += '</div>'
// innerHTML += '<div class="quantity">' + data[dt].qt+ '</div>'
innerHTML += '</div>'
innerHTML += '</div>'
let abc={
code:data[dt].aa.code,
data:data[dt]
}
clickEventMethod.push(abc);
}
this.totalAmount = amount;
this.totalSaving = savings;
// outputHtml += '</ion-list>';
let footerHtml = '<div class="row cartfooter">'
footerHtml += '<div col-4><p>Total amount</p>' + this.currency.transform(this.totalAmount, 'INR') + '</div>'
footerHtml += '<div col-4><p>Total amount</p>' + this.currency.transform(this.totalSaving, 'INR') + '</div>'
footerHtml += '<div col-4><p>Say <strong>Checkout</strong> to checkout all items</p></div>'
console.log(clickEventMethod,'clickEventMethod')
outputHtml += innerHTML + footerHtml + '</div></div>';
this.appenData.nativeElement.insertAdjacentHTML('beforeend', outputHtml);//Appending the data at the end of the ion-content // break;
HTML
<ion-header [ngClass]="!isFromHome ? 'leftPaddingCssTitle':'cssTitle'">
<ion-navbar color="danger">
<ion-title>{{headerName}}</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div class="hint">
<p>To go back , say <b>Go Back</b></p>
<p>To Go cart , Say <b>Open Cart </b> or <b>Go to Cart</b></p>
</div>
<div class="main" #appenData id="main">
</div>
<ion-content>

Related

How to get each array value outside loop to modal?

I have this in JS and the code below. I want to send the data-id into modal and also when closing the modal to dismiss the data-id. how can I do that using javaScript???
fetch("https://data.uk/api/" + $searchValue).then(
res => {
res.json().then(
data => {
if (data.length > 0) {
var temp = "";
temp += "<thead>";
temp += "<tr>";
temp += "<th>ID</th>";
temp += "<th>Force Name</th>";
temp += "<th>Details</th>";
temp += "</tr>";
temp += "</thead>";
temp += "<tbody>";
data.forEach((itemData) => {
temp += "<tr><td>" + itemData.id + "</td>";
temp += "<td>" + itemData.name + "</td>";
temp += "<td><a href='#' data-id='" + itemData.id + "' data-toggle='modal' data-target='#myModal'>More Detail</a></td></tr>";
});
temp += "</tbody>";
document.getElementById('data').innerHTML = temp;
}
}
)
}
)
and I want to get each data-id value into modal using this
$("myModal").on("show.bs.modal", function(e) {
var b = $(e.relatedTarget);
var r = b.data("id");
var modal = $(this);
modal.find("#me").text(r);
})
and this is my modal, I want when I open the modal to be able to capture the data-id and display it in id="me"
<div class="modal-body" id="modal-body">
<div class="row m-0">
<div class="col-4">
People name & twitter
</div>
<div class="col-8">
Descriptions
<h2 id="me"></h2>
</div>
</div>
</div>
You can access data-... attribute with dataset property, e.g. given
<div id="my-element" data-id="myData"></div>
you can get it with
document.getElementById("my-element").dataset.id

Combine Slick Slider with Bootstrap 4

I have this next issue in which I am having quite a significant problem.
First of all, I am trying to integrate three div into my slider and all of them retain a Bootstrap 4 skeleton.
The code would be like this and furthermore it is being generated from another Jquery function in which I am inserting info from a Database. Therefore, I am putting this info into one of each card.
//FUNCIONES
//Crear especialista
function CrearEspecialistaCard(especialista, mostrarNombreEspecialidad) {
let cardHTML = "";
cardHTML += '<div><div class="col-xs-12 col-lg-3 col-md-3 float-left has_border_grey border_10 px-0 overflow-hidden mr-2 profile-box">'
+ '<div class="card d-inline"><div class="col-lg-6 col-md-6 bg-light float-left py-2 text-md-left text-center" style="z-index:101;"> ';
cardHTML += '<h2 class="text-secondary profile-name">' + ((especialista.sexo == "F") ? "Dra. " : "Dr. ")
+ especialista.nommed + " " + especialista.apemed + '</h2>' +
'<button class="btn btn-secondary btn-profile btn-sm my-2" data-toggle="modal" data-target="#modalDoctor' + especialista.idEspecialista + '"'
+ '>Ver perfil' + '</button>';
cardHTML += '<h3 class="spec-title">' + especialista.descesp + '</h3>' + '<h4 class="center-title">' +
'' + '</h4>'+ '<h5 class="prov-title mb-1">' + especialista.provincias + '</h5>';
cardHTML += '<p id="reservarCita" class=""> RESERVAR CITA</p>' +
(especialista.teleConsulta === true) ?
'<a class="d-inline-block mr-1" href="/videoConsulta"><img class="bg-purple py-1 px-1" src="/Content/Img/videoconsulta30.png" style="max-width:30px;" />' +
'</a>' : '';
cardHTML += (especialista.videoConsulta === true) ?
'<a class="d-inline-block mr-1" href="/teleConsulta"><img class="bg-purple-red py-1 px-1" src="/Content/Img/teleconsulta-30.png" style="max-width:30px;" />' +
'</a>' : '';
cardHTML += (especialista.consulta === true) ? '<a class="d-inline-block mr-1" href="/pedirCita">' +
'<img class="bg-light-purple py-1 px-1" src="/Content/Img/presencial30.png" style="max-width:30px;" />' +
'</a>' : '';
cardHTML += '</div>';
cardHTML += ' <div class="col-md-6 float-left" style="z-index:100;">' +
'<img class="profile-img img-fluid" src="/Content/Img/Medicos/CuadroAsistencial/FORMATO-MEDICOS.jpg" alt="Doctor" />' +
'</div>';
if (mostrarNombreEspecialidad != undefined && mostrarNombreEspecialidad == true) {
cardHTML += '<br /><span style="font-size:small;" class="colorcard bold">' + especialista.descesp + '</span>';
} else {
cardHTML += '<br />';
}
cardHTML += '</div></div></div>';
return cardHTML;
}
I am going to show you where I create the row which inserts one of every card with an anonymous function.
const MuestraEspecialistasFavoritos = (qRow) => {
let resultadoHTML = "";
let modalHTML = "";
resultadoHTML += '<div class="preview-carousel">'; // this is where I generate the class for my carousel
for (var a = 0; a < globalModeloFavoritos.length; a++) {
let toto = ca_model.listaEspecialistas.filter(b => b.idEspecialista == globalModeloFavoritos[a]);
if ( toto ) resultadoHTML += CrearEspecialistaCard(toto[0] , false);
if( toto )
var doctor = toto[0];
modalHTML += loadModal(doctor, toto[0].idEspecialista);
}
modalesRecientes.html(modalHTML);
resultadoHTML += '</div>';
qRow.html(resultadoHTML);
}
When I already have constructed my cards, which in this case they are functioning and being displayed as I want to, I am calling the slick slider so that I can interpret one of every card as one unique slider.
$('.preview-carousel').slick({
slidesToShow: 2,
slidesToScroll: 1
});
My slick.js is loaded as I already checked but it doesn't do absolutely nothing.
FYI every one of the cards generates a div firstly with no classes and no ids so I can be able to interpret every one of the items as if they were items of the slider.
Ok, found it already.
It wasn't that hard actually.
I was trying to run the slick function inside a document ready function.
With an on load functions, it works perfectly.
$(window).on('load', function() {
$('.preview-carousel').slick({
slidesToShow: 2,
slidesToScroll: 1
});
});

Bootbox message box doesn't fit content

bootbox.confirm({
title: "請輸入綁定手機號碼",
message:
'<div class="col-xs-12">'
+ '<form class="form-horizontal">'
+ '<div class="form-group">'
+ '<label class="col-xs-12" style="text-align: left">帳號(您的手機號碼):</label>'
+ '<div class="col-xs-5">'
+ '<select class="form-control" id="countryCode-bootbox" name="countryCode-bootbox">'
+ '<option value="+93">Afghanistan +93</option>'
+ '<option value="+355">Albania +355</option>'
+ '<option value="+213">Algeria +213</option>'
+ '<option value="+1684">American Samoa +1684</option>'
+ '<option value="+263">Zimbabwe +263</option>'
+ '</select>'
+ '</div>'
+ '<div class="col-xs-7">'
+ '<input type="text" class="form-control" id="cellphone-bootbox" name="cellphone-bootbox">'
+ '</div>'
+ '</div>'
+ '</form>'
+ '</div>',
callback:
function(result) {
if(result == false) {
return;
}
register3rdPartyUser(flag, $('#countryCode-bootbox').val(), $('#cellphone-bootbox').val());
}
});
As you can see, there are two horizontal lines inside the overall box which I believe are the boundaries of the message content. The bottom line doesn't come after the message content when I'm using HTML for my string. How can I fix this issue? Is it a bug?

how to view a url as a sting using htmlString

I want to view all the items in my database and i managed to retrieve all except for the image.
This is my code:
htmlString += '<div class="col-md-4"> ImageShouldGoHere </div>';
htmlString += '<div class="col-md-8">';
htmlString += '<div class="col-md-12 listing-title"> ' + data[i].title + ' </div>';
htmlString += '<div class="col-md-12 category-text"> ' + data[i].category + ' </div>';
The URL of the image is located in data[i].previewImage how can i view the URL as an image in the place of ImageShouldGoHere?
putting the image url as a src of img tag would do the job.
htmlString += '<div class="col-md-4"><img src="' + data[i].previewImage + '" /></div>';

Autodividers in listview in JQM using filter

I am using autodividers in listview in JQM and populating new "pages" which works fine when all the list is displayed but when user filters the list, the corresponding page does not display. I'm sure I'm missing something obvious so would appreciate any help.
js
$(document).ready (function() {
$.getJSON("eur_countries_array.json", function (data) {
var countries = [];
for (var obj in data){
countries.push({
title: data[obj].title,
flag: data[obj].flag,
population: data[obj].population,
avg_annual_growth: data[obj].avg_annual_growth,
date: data[obj].date
});
}
// call sort function
countries.sort(compare);
// read through array
var listHTML = "";
for (var i=0; i < countries.length; i++) {
// for each country add flag and title to list
listHTML += '<li><img class="ui-li-icon ui-corner-none alt="'+ countries[i].flag + 's flag" src="flags/16/' + countries[i].flag +'.png" >' + countries[i].title + '</li>';
// Append new "pages" after "home" page for each country
var pHTML = '<div data-role="page" id="' + countries[i].flag + '">';
pHTML += '<div data-role="header"><h1>' + countries[i].title + '</h1><a data-rel="back">Back</a></div>';
pHTML += '<div role="main" class="ui-content" class="country_details">';
pHTML += '<div class="center"><img class="flag_display" alt="'+ countries[i].flag + 's flag" src="flags/64/' + countries[i].flag +'.png" ></div></div>';
pHTML += '<div><p class="center">Population of ' + countries[i].title + ' is ' + countries[i].population + '</p></div>';
pHTML += '<div><p class="center">Average annual growth: ' + countries[i].avg_annual_growth + '</p></div>';
pHTML += '<div><p class="center">Statistics correct as of: ' + countries[i].date + '</p></div>';
pHTML += '</div>';
console.log(pHTML);
$("body").append(pHTML);
}
// Display countries list
// call the refresh method to update the visual styling after adding new elements
$("#countryList").empty().append(listHTML).listview("refresh");
});
});
html
<div data-role="page" id="home">
<div data-role="header">
<h2>European Countries</h2>
</div>
<div role="main">
<ul id="countryList" data-role="listview" data-autodividers="true" data-filter="true" data-inset="true">
<li></li>
</ul>
</div>
<div data-role="footer">
</div>
</div><!-- page -->