I have a json data as below:
Json Data
{"APPLICABLE_DATE":"2016-01-11,2016-01-12,2016-01-13"}
Here i am trying to split each date from json and trying to supply for HTML using append. How can i get each date and supply to my HTML
Html to Append
<input type="text" name="l_date_'+index+'" value="'+available_dates.APPLICABLE_DATE+'" />
JS
function AddDate_Row_For_Html(available_dates)
{
//available_dates as Json data
//How can i split dates and create above html
}
var x = {"APPLICABLE_DATE":"2016-01-11,2016-01-12,2016-01-13"};
var dates = x.APPLICABLE_DATE;
var date_arr = dates.split(",");
date_arr.forEach(function(el, index){
$("#any_element").append("Element: " + el + " Index" + index);
});
APPLICABLE_DATE
. ,
and to get array of dates. el
to any element in its callback. Let's complete your function in such way:
function addDate_Row_For_Html(available_dates) // assuming available_dates is raw json
{
var dataObj = JSON.parse(available_dates);
var date_arr = dataObj.APPLICABLE_DATE.split(',');
date_arr.forEach(function(item, i){
$("#container").append('<input type="text" name="l_date_'+(i+1)+'" value="'+item+'" />');
});
}
addDate_Row_For_Html('{"APPLICABLE_DATE":"2016-01-11,2016-01-12,2016-01-13"}');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.