Popover is not working for json multiple values - json

[
{
"id" : 1,
"name" : "clevin",
"description" : "Version 1 : some desc",
"info" : [{
"id" : 2,
"name" : "abc",
"size" : "5 GB",
"used" : "25%"
},
{
"id" : 3,
"name" : "def",
"size" : "10 GB",
"used" : "15%"
},
{
"id" : 4,
"name" : "ghi",
"size" : "20 GB",
"used" : "5%"
}],
}]
This is my json file. When ever i mouse over "info.name"[abc, def, ghi] popover will display "name", "size" and "used".
but my issue is "abc" is the first value , when ever i mouseover it display value as expected. but when i mouseover "def" and "ghi" nothing is happened :(.
<ul type="none">
<li>
<label id="vol-label" class="muted">Info :</label>
{{#info}}
<span id="value"><a><u>{{name}}</u></a></span>
<span id="info-popover-title" class="hide">{{name}}</span>
<div id="info-popover-content" class="hide">
<p>Size : {{size}}</p> <p> Used : {{used}}</p><p> Status : {{status}}</p>
</div>
{{/info}}
</li>
</ul>
This is my template(mustache).
following is my view part(backbone.js)
events: {
"mouseenter #value" : "showDetails",
"mouseleave #value" : "hideDetails" ,
},
showDetails : function() {
this.$("#value").popover({
html : true,
title: function() {
return $("#info-popover-title").html();
},
content: function() {
return $("#info-popover-content").html();
}
});
this.$("#value").popover('show');
},
hideDetails : function() {
this.$("#value").popover('hide');
},
Please see my both screen shot to understand the issue. In fist screens hot see am getting all json info values "abc" "def" and "ghi" . in 2nd screen shot if i mouse over am getting "abc" values. but "def" and "ghi" value is not at all displaying. am not figure it out what is the issue :(.
I need to popove "def" and "ghi" values also. But i think something is wrong in my logic. Thanks in advance. This is really a rare issue for me might be others also.
If i use class insted of id following is the screen shot :(

2 things that you need to change here. First, is to use class to define for popovers instead of id. And the second is to abstract each <li> into its own view. Currently, you have one view that loops through the entire collection. All your events are currently tied to this one view. Doing those things I mentioned should fix this issue.
You can do something like this to have the become its own view which carries it's own sub-element. Just wrote this quickly and haven't tested but the idea is something like this. I'm not really sure which popover library you're using but the idea is generally the same.
Edit: Didn't realized you were using Mustache/Handlebars, so here's the JS Fiddle. Code

Now if you try to call each object it should work.
var abc =
{
"id" : 1,
"name" : "clevin",
"description" : "Version 1 : some desc",
"info" : {
"id" : 2,
"name" : "abc",
"size" : "5 GB",
"used" : "25%"
}
};
var def =
{
"id" : 3,
"name" : "def",
"size" : "10 GB",
"used" : "15%"
};
var ghi = {
"id" : 4,
"name" : "ghi",
"size" : "20 GB",
"used" : "5%"
};
var output =
{
show : function()
{
return abc["info"];
}
};
console.log(output.show());

Related

F# - Compare 2 JsonValue'

I have 2 Json values that are similar, but there are some differences.
Json1:
{
"id": "1",
"people" : [
{
"Id" : 1421,
"Name" : "Jackson",
"Age" : 21,
"Status" : "Available"
},
{
"Id" : 5916,
"Name" : "Steven",
"Age" : 22,
"Status" : "Available"
}
],
"totalRecords" : 2
}
Json2:
{
"id": "1",
"people" : [
{
"Id" : 1421,
"Name" : "Jackson",
"Age" : 21,
"Status" : "Available"
},
{
"Id" : 5916,
"Name" : "Steven",
"Age" : 22,
"Status" : "Unavailable"
},
{
"Id" : 1337,
"Name" : "Alice",
"Age" : 19,
"Status" : "Available"
}
],
"totalRecords" : 3
}
I'd like to know if there's a way to compare the two Jsonvalues. At the moment I de-serialize the data into a type and then use the Id's and the status' to see if anythings changed. I then pick out the parts that are different (In the example it'd be Steven and Alice) and add them to a sequence for later.
I'd like to reverse a few of the steps. I'd like too compare the json, find the differences, deserialize them and then add them to the sequence, or add them to the sequence then de-serialize the whole sequence. Either way, same result.
Any ideas?

MongoDB Change/Update Subdocument Field

I currently have a Mongo DB database with one collection ('locations') with one document:
{
"_id" : ObjectId("5875653b89513c8328416522"),
"name" : "Starcups",
"address" : "125 High Street, Reading, RG6 1PS",
"rating" : 3,
"facilities" : [
"Hot drinks",
"Food",
"Premium wifi"
],
"coords" : [
-0.9690884,
51.455041
],
"openingTimes" : [
{
"days" : "Monday - Friday",
"opening" : "7:00am",
"closing" : "7:00pm",
"closed" : false
},
{
"days" : "Saturday",
"opening" : "8:00am",
"closing" : "5:00pm",
"closed" : false
},
{
"days" : "Sunday",
"closed" : true
}
],
"reviews" : [
{
"author" : "Simon Holmes",
"id" : ObjectId("5875663389513c8328416523"),
"rating" : 5,
"timestamp" : ISODate("2013-07-15T23:00:00Z"),
"reviewText" : "What a great place. I can't say enough good things about it."
}
]
}
I need to alter the field "id" (part of the subdocument reviews) to "_id". I have tried, using other similar examples on StackExchange, the following code to no avail:
db.locations.update({}, {$rename:{"reviews.id":"reviews._id"}}, false, true);
But I receive the following error:
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 16837,
"errmsg" : "cannot use the part (reviews of reviews.id) to traverse the element ({reviews: [ { author: \"Simon Holmes\", id: ObjectId('5875663389513c8328416523'), rating: 5.0, timestamp: new Date(1373929200000), reviewText: \"What a great place. I can't say enough good things about it.\" } ]})"
}
})
I get the same error when I try to alter any other field. Could someone point me in the right direction?
Update:
This seems to be a problem assessing the subdocument field as the following code executes fine:
db.locations.update({}, {$rename:{"name":"names"}}, false, true);
I have also tried searching through the relevant documentation: https://docs.mongodb.com/manual/reference/operator/update/rename/
That's because Reviews is an Array
You cannot $rename to do that , instead you need to $set the new name and $unset the old one

Get the value for one object given the value of another object in JSON and Angularjs

Given this JSON:
{
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" :
{
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers":
[
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
}
Is there a way in Angularjs to get the value of "number" when the value of "type" is equal to iPhone OR home?
I think this would be pretty easy to do with something like JSONPath but I'm having a hard time getting JSONPath to play nicely with Angular. If there is an easy way to do it in Angular I love to hear about it.
You can use $filter service just don't forget to inject it into controller. please see here:
http://jsbin.com/nacam/1/edit?html,js,output
app.controller('firstCtrl', function($scope, $filter){
$scope.user = {
"firstName": "John",
"lastName" : "doe",
"age" : 26,
"address" :
{
"streetAddress": "naist street",
"city" : "Nara",
"postalCode" : "630-0192"
},
"phoneNumbers":
[
{
"type" : "iPhone",
"number": "0123-4567-8888"
},
{
"type" : "home",
"number": "0123-4567-8910"
}
]
};
//I've made assumption that only one number exist for iphone but of not you just get first one
$scope.iphoneNumber = ($filter('filter')($scope.user.phoneNumbers, "iPhone"))[0].number;
});
You would first need to access the phoneNumbers array of the object.
So something like this.
obj = { ..your object.. }
var phoneNumbers = obj.phoneNumbers;
If you are doing this in markup, you could use an angular filter with the pipe syntax.
{{ expression | filter }}
If you are doing this in the controller, you can still use an angular filter with the controller syntax:
$filter('filtername')(arg1,arg2);
Here is a link to filters.
https://docs.angularjs.org/guide/filter
Filters are very powerful can you can even write your own custom filters to do pretty much whatever you need.
Hope this helps.

Apex JSON parsing error

I am getting the following error in my code:
System.JSONException null Don't know the type of the Apex object to
deserialize at [line:1, column:1] 11 (System Code)
Class.FactorLab.FactorLabWebservices.RetrieveUsersFromFactorLab: line
60, column 1 Class.FactorLab.PullUsers.execute: line 61, column 1
Here is the code in question:
public static List<FactorLabPullUser> RetrieveUsersFromFactorLab(List<String> ids){
HttpRequest req = getHttpRequest(baseUrl + '/ws/sfdc/people/retrieve', 'POST');
req.setBody(JSON.serialize(ids));
req.setHeader('Content-Type', 'application/json');
if(Test.isRunningTest()){
return null;
}
HttpResponse res = sendRequest(req);
// This is the line with the error
List<FactorLabPullUser> flusers = (List<FactorLabPullUser>)JSON.deserialize(res.getBody(), Type.forname('List<FactorLabPullUser>'));
return flusers;
}
I'm sure that it's receiving valid JSON, but I'm not sure the exact JSON it's receiving when it gets this error. It could simply get an empty array:
[]
It could also get something like this:
[ { "SFDCStatus" : "RETRIEVED",
"address" : "123 Fake St.",
"addressLine1" : "Address1",
"addressLine2" : "Address2",
"city" : "San Francisco",
"companyName" : "Big Cheese, Inc.",
"deleted" : false,
"email" : "james.willard#fake.com",
"firstName" : "James",
"hireDate" : "2000-04-15T00:00:00Z",
"id" : 39,
"lastName" : "Willard",
"lastUpdated" : "2011-11-23T05:44:03Z",
"myersBriggs" : "SFDC",
"name" : "James Willard",
"phone" : "415-555-1212",
"position" : "Big Chief",
"regions" : [ { "deleted" : false,
"id" : 445,
"name" : "Mountain"
} ],
"state" : "CA",
"yearsExp" : 20.0,
"zip" : "94131"
},
{ "SFDCStatus" : "RETRIEVED",
"deleted" : false,
"firstName" : "Daniel",
"id" : 40,
"lastName" : "Adams",
"lastUpdated" : "2011-11-23T05:44:03Z",
"name" : "Daniel Adams"
}
]
Any ideas? Someone told me this was a Salesforce.com bug, but it seems like even if that were true, there must be a workaround.
Looks like you may not be casting properly. I haven't played around with the serialize/deserialize native JSON much yet and have preferred to do my own parsing/persisting. But your line causing the error looks suspicious:
List<FactorLabPullUser> flusers = (List<FactorLabPullUser>)JSON.deserialize(res.getBody(), Type.forname('List<FactorLabPullUser>'));
I think it should look like the following:
List<FactorLabPullUser> flusers = (List<FactorLabPullUser>)JSON.deserialize(res.getBody(), List<FactorLabPullUser>.class);
I can't see for sure from your code snippit but if the FactorLabPullUser class is an inner class you will need to fully qualify it for Type.forName() to work.
I would expect to see something like this:
List<FactorLabPullUser> flusers = (List<FactorLabPullUser>)JSON.deserialize(res.getBody(), Type.forname('List<Outerclass.FactorLabPullUser>'));
I think that the bug you mention is to do with the use of the .class method - I have noticed this not always return a valid Type.

insert table into <li> when using jsTree & json

Can I somehow insert a table inside <li> when using
jsTree (1.0) and
json?
let's say in this code where I want to insert table for
both node and
leaf.
Why? To display more things than only a name and using nice formatting.
"data" : [
{
"data" : "A node",
"children" : [ "Child 1", "Child 2" ]
},
{
"attr" : { "id" : "li.node.id" },
"data" : {
"title" : "Long format demo",
"attr" : { "href" : "#" }
}
}
]
update:
it seems to me that I can use html_titles. But could somebody give me an example how to insert whole table and get cell data from variables?
Update2:
whether I use
"data" : "<table><tr><td>Site name</td><td>variable 1</td><td>variable 2</td></tr></table>",
or
"title" : "<table><tr><td>Site name</td><td>variable 1</td><td>variable 2</td></tr></table",
the table is placed on a new line. Not next to the tree icon. Can I fix that somehow?
Expanding on the original post to help others trying to do the same:
$(function () {
$("#demo1").jstree({
"json_data" : {
"data" : [
{
"data" : "<table style='display: inline-block'><tr><td>Site name</td><td>variable 1</td><td>variable 2</td></tr></table>",
"children" : [ "Child 1", "Child 2" ]
},
{
"attr" : { "id" : "li.node.id" },
"data" : {
"title" : "Long format demo",
"attr" : { "href" : "#" }
}
}
]
},
"core" : {"html_titles" : true},
"plugins" : [ "themes", "json_data" ]
});
});
The key is to allow html in the titles which is set in the core options as well as the table style
I thought it needs to be solved on javascript level but <table style='display: inline-block'> does the trick
Addon: The "text" you supply is actually treated as html by default.
core: {
data: [{
id: "ID",
parent: "#",
text: "<span>Individual</span>",
icon: 'fa fa-star text-warning'
},}]}