Displaying the contents in the <td> vertically - html

I am trying to extract the json values and put them into a html table.Although i am successful in inserting the data into the table,i couldnot insert them vertical.Below mentioned screenshot explains the problem.
In the table, the values that are being printed in the row are meant to be displayed vertically.i.e they come under the column name.
Attached is the structure of my JSON file.
{
"meta":
{
"view":
{
"columns":[
"cachedContents":{
"name:"name"
}]}}}
more details are available at:
https://data.baltimorecity.gov/api/views/hyq3-8sxr/rows.json
I am trying to print the values that are present in the name column. Below posted is the code.
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
<style>
#result
{
color:red;
}
</style>
</script>
<script type="text/javascript">
$(document).ready(function()
{
var row = $("<tr/>")
$("#personDataTable").append(row);
$.get("https://data.baltimorecity.gov/api/views/hyq3-
8sxr/rows.json",function(data)
{
$.each(data.meta.view,function(i,obj)
{
if(i=="name")
$("#results").append("<p align='center'>"+obj+"
</p>");
if(i=="description")
$("#results").append("<p align='center'>"+obj+"
</p>");
if(i=="columns")
var length = data.meta.view.columns.length;
for(var ind=0;ind<length;ind++)
{
if(null!=obj[ind].name)
{
$("#results").append("<tr>
<td>"+"name"+obj[ind].name+"</tr></td>");
}
if (null!=obj[ind].cachedContents)
{
$.each(obj[ind].cachedContents,function(j,obj1)
{
if (j=="top")
{
var toplength = obj1.length;
for (k=0;k<toplength;k++)
{
if(null!=obj1[k].item)
{
$("#results").append("<li>"+obj1[k].item+"
</li>");
if(obj[ind].name=="name")
{
row.append($("<td
align='vertical'>" + obj1[k].item + "</td>"));
}
if(null!=obj1[k].item.human_address)
{
$("#results").append("
<li>"+obj1[k].item.human_address+"</li>");
}
}
}
}
}
);
}
}
I am trying to print the values that are present in the name column vertically
Any Suggestions would be highly helpful.

Related

How To Put A Number In Front Of Every Suggestion Corretcly?

Detail Of The Problem
As title, I am using Google App Script and Google Docs API's Batchupdate, trying to put number in front of every suggestion. However, I can place it correctly at the very first one, but it starts to deviate after the first one.
Result I Currently Have
Please refer to the image below.
What I have Tried
Below is the snippet I currently have
function markNumberInFrontOfMark(fileID) {
fileID = "MYFILEID";
let doc = Docs.Documents.get(fileID);
let requests = doc.body.content.flatMap(content => {
if (content.paragraph) {
let elements = content.paragraph.elements;
return elements.flatMap(element => element.textRun.suggestedDeletionIds ? {
insertText: {
text: "(1)",
location: {
index: element.startIndex
}
}
} : []);
}
return [];
});
Docs.Documents.batchUpdate({requests}, fileID);
return true;
}
Result I Want To Have
Please refer to the image below
Post I Refer to
How to change the text based on suggestions through GAS and Google DOC API
Here is an example of how to insert text. In this case I am adding 3 characters "(1)" for example. If the number of additions exceeds 9 you will have to adjust the number of characters added.
function markNumberInFrontOfMark() {
try {
let doc = DocumentApp.getActiveDocument();
let id = doc.getId();
doc = Docs.Documents.get(id);
let contents = doc.body.content;
let requests = [];
let num = 0;
contents.forEach( content => {
if( content.paragraph ) {
let elements = content.paragraph.elements;
elements.forEach( element => {
if( element.textRun.suggestedDeletionIds ) {
num++;
let text = "("+num+")"
let request = { insertText: { text, location: { index: element.startIndex+3*(num-1) } } };
requests.push(request);
}
}
);
}
}
);
if( requests.length > 0 ) {
Docs.Documents.batchUpdate({requests}, id);
}
}
catch(err) {
console.log(err)
}
}
And the resulting updated document.

Monaco-Editor Single String From Database

Been researching for the last couple of days and still no result. I have a back-end database that saves text entered in the Monaco-Editor. However, text will not display/load if there are new line returns (\r\n) in the string. The only I can get the text to display is to remove the line returns.
Here is some client-side code.
<div id="container" style="width:590px;height:400px;border:1px solid grey;white-space:pre-wrap;"></div>
//saving to hidden value
<input type="hidden" runat="server" id="editorValue" />
require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' } });
require(["vs/editor/editor.main"], function () {
var editor = monaco.editor.create(document.getElementById('container'), {
value: ['<%=MyJSText%>'].join('\n'),
language: 'javascript'
});
jQuery(document).ready(function ($) {
jQuery("#<%=linkOK.ClientID%>").on('click', function () {
getVal = editor.getValue();
document.getElementById("<%=editorValue.ClientID%>").value = getVal;
});
});
Some server side code
protected string MyJSText
{
get
{
if (EnableIDEditor)
{
return Server.HtmlDecode(TemplateRevision.JsScripts.Replace(Environment.NewLine, " "));
}
else
{
return Server.HtmlDecode(TemplateRevision.JsScripts);
}
}
}
I'd like the text entered into the monaco-editor box to display with line-breaks. Any help would be greatly appreciated.
Finally solved the problem by adding the following code on the server-side.
protected string MyJSText
{
get
{
if (EnableIDEditor)
{
return Server.HtmlDecode(TemplateRevision?.JsScripts?.Replace(System.Environment.NewLine, "\\\r\\n"));
}
else
{
return Server.HtmlDecode(TemplateRevision.JsScripts);
}
}
}
The trick was to use .Replace(System.Environment.NewLine, "\\r\n")) and the line breaks showed appropriately. Hope this helps someone who is looking to dynamically insert text into the monaco-editor.

VisJs How to import json data without creating duplicate edges?

How can I import new json data (gephiJSON) without duplicating edges in my existing data?
My code is as simple as that:
var parsed = vis.network.gephiParser.parseGephi(gephiJSON, parserOptions);
nodes.update(parsed.nodes);
edges.update(parsed.edges);
I am afraid I did not find any option or function to avoid/check duplicates.
Appreciate any help.
*I have no control over the imported data to avoid duplicates.
I use nodes.update method only to update existing network. To create new ones I use nodes.add. So, it's important to check existing data in your network before trying to add. I used a double loop routine plus a splice method for the JSON to delete duplicated nodes and edges. My code was like this (please be patient with me, I'm new in JavaScript) :
function recibedatos() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
fixedResponse = http_request.responseText;
jsonObj = JSON.parse(fixedResponse);
try {
for (var i=0;i<jsonObj.nodos.length;i++) {
for (var j=0;j<nodes.length;j++) {
if (jsonObj.nodos[i].id==nodes.get()[j].id) {
jsonObj.nodos.splice(i,1);
i-=1;
break;
}
}
}
nodes.add(jsonObj.nodos);
}
catch (err) {
alert(err);
}
try {
for (var i=0;i<jsonObj.vinculos.length;i++) {
for (var j=0;j<edges.length;j++) {
if (jsonObj.vinculos[i].to==edges.get()[j].to && jsonObj.vinculos[i].from==edges.get()[j].from && jsonObj.vinculos[i].label==edges.get()[j].label) {
jsonObj.vinculos.splice(i,1);
i-=1;
break;
}
}
}
edges.add(jsonObj.vinculos);
}
catch (err) {
alert(err);
}
} else {
alert("Ocurrio un problema con la URL.");
}
fixedResponse=null;
jsonObj=null;
}
}

AngularJS display specific String in HTML

I'm still in process learning Angular.
For my current project I need to display HTML (eg: <h1>note1</h1><span>my first note</span><br><h1>note2</h1><span>my second note</span>) in my view. I know everyone will suggest to use ng-bind-html, but that is not what I want.
What I want is, i want to do checking if string HTML have note2 then display my second note.
In controller I know how to find string note2 which is use .match.
JSON
items =
[
{
"description": "<h1>note1</h1><span>my first note</span><br><h1>note2</h1><span>my second note</span>"
}
]
In controller find String note2
angular.forEach(items, function(value, key) {
if (value.description.match("note2")) {
console.log(value.description);
// will output HTML <h1>note1</h1><span>my...
}
else {
console.log("string not found");
}
});
I can do till find String note2, but to display my second note I don't have any idea.
Can someone help me with this,
thanks..
I haven't test this, but maybe you can use split function
angular.forEach(items, function(value, key){
if(items.description.match("note2")){
console.log(items.description);
var noteValues = items.description.split("<h1>note2</h1>");
$scope.mySecondNote = noteValues[1]; // value is <span>my second note</span>
}else{
console.log("string not found");
}
});
EDIT
Plunker DEMO here
It should be value.description., because items is an array
angular.forEach(items, function(value, key) {
if (value.description.match("note2")) {
}
DEMO
var app = angular.module('todoApp', []);
app.controller("dobController", ["$scope",
function($scope) {
items = [{
"description": "<h1>note1</h1><span>my first note</span><br><h1>note2</h1><span>my second note</span>"
}];
angular.forEach(items, function(value, key) {
if (value.description.match("note2")) {
console.log(value.description);
// will output HTML <h1>note1</h1><span>my...
} else {
console.log("string not found");
}
});
}
]);
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<title>To Do List</title>
<link href="skeleton.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
<script src="MainViewController.js"></script>
</head>
<body ng-controller="dobController">
</body>
</html>
Change to
if (items[0].description.match("note2")) {
console.log(items[0].description);
// will output HTML <h1>note1</h1><span>my...
}
else {
console.log("string not found");
}

JSON - Checking for a property in a deeply nested JSON

JSON structure:
{
"codes":[
{
"id":"1",
"code":{
"fname":"S",
"lname":"K",
"dateofbirth":{
"month":"12",
"day":"02",
"year":"1998"
}
}
},
{
"id":"2",
"code":{
"fname":"M",
"lname":"D",
"dateofbirth":{
"month":"10",
"day":"02",
"year":"1998"
}
}
}
]
}
I want to loop through each code AND dateofbirth and alert if the month is 12. If the month is not 12, then do nothing.
success: function(data){
var x;
for (x = 0; x < data.codes.length; x++){
var count=0;
for (property in data.codes[x].code) {
count++;
}
}
}
How can I loop through dateofbirth and check for the value of month?
Example of JSON structure with more than 1 property under 'code' that can be an object. So I want to loop through all the properties within code and check for the value of the month property instead of manually checking for a particular property.
{
"codes":[
{
"id":"1",
"code":{
"fname":"S",
"lname":"K",
"dateofbirth":{
"month":"12",
"day":"02",
"year":"1998"
},
"membership":{
"month":"12",
"day":"12",
"year":"2011"
}
}
},
{
"id":"2",
"code":{
"fname":"M",
"lname":"D",
"dateofbirth":{
"month":"10",
"day":"02",
"year":"1998"
},
"membership":{
"month":"10",
"day":"12",
"year":"2011"
}
}
}
]
}
mycodes=// the object from parsed JSON
for (i=0; i<mycodes.codes.length; i++) {
if (mycodes.codes[i].code.dateofbirth.month=="12") {
alert("Code " + mycodes.codes[i].id + " has birth month of 12");
}
}
BTW, you really should store birthdates as numbers, not strings.