Angularjs - Json Emittted has Index number on sub object - javascript

I have a form that has three fixed questions, each question is followed by two drop down control for a user to select.
Since my number of questions are fixed and will remain fixed , I am not using ng-repeat to render my questions.
In the end, I want my structure to be represented as
Attendee
-Name
-Email
-EventCollection
---Event1
----Event1Name
----IsAccepted
----TotalAdults
----TotalChildren
---Event2
----EventName
----IsAccepted
----TotalAdults
----TotalChildren
ng-model for my event fields for e.g. is set as
indata.im.EventList[0].IsAccepted, indata.im.EventList[1].IsAccepted and indata.im.EventList[2].IsAccepted
Issue I am facing here is that the JSON emitted has additional index attached to it. "0" , "1", "2". How to remove this index numbers that are getting added here
{
"Name":"Kunal",
"EventList":{
"0":{
"TotalAdults":"3",
"TotalChildren":"2",
"IsAccepted":"1",
"EventName":"Sangeet"
},
"1":{
"TotalAdults":"1",
"TotalChildren":"2",
"IsAccepted":"1",
"EventName":"Marriage"
},
"2":{
"TotalAdults":"2",
"TotalChildren":"1",
"EventName":"Reception"
}
}
}

Related

How to display json with multiple dimensional array in typescript

TypeScriptArray
Greetings. I have a problem with the array. I don't know how to display multiple dimensional arrays. This is the picture of my code on the left side and on right, I have JSON that I must display in Insomnia for the test. You can see
"lineups": {
"home_team": {
"starting_lineups": [
{
"player": "Asghar A. (C)",
"player_country": "Afghanistan"
},
....
I must display all the players and countries. All lines work well but for player and player_country, when I display, program print "undefined".
Thanks!
starting_lineups is array:
If you want to to use player_country from first array item:
hometeam.lineups.home_team.starting_lineups[0].player_country

jQuery SheepIt demo indexes are wrong using nested forms

I am using the demo here: http://www.mdelrosso.com/sheepit/index.php?lng=en_GB&sec=demo3
But if you have two of the outer forms (addresses) and two each for the inner forms (numbers) and inspect the elements you'll notice the names of the inputs still have the #index# and/or #index_phone# strings in the index names.
If you try to submit the form then, the field data is lost (since only the latest copy of that name is kept). I've tried debugging the JavaScript so I can patch it, but I'm not seeing where it's wrong. It seems like the normalizeForms function isn't handling nesting correctly.
What can I do to correct the code so the indexes perform as expected? (That is: so that an input of two addresses (A and B), each with two phone numbers (A1, A2 and B1, B2) gives me a POSTed value like:
"people" : [
0 : {
"addresses" : "A",
"phones" [ 0 : "A1", 1: "A2" ]
},
1 : {
"addresses" : "B",
"phones" [ 0 : "B1", 1: "B2" ]
}
]
(Note: I'm not looking for that exact format; I can parse any output, I just need to get all of the data from the client to the server with meaningful indexes and without conflicts.)
There appear to be some fundamental logic issues with the index 'normalization' side of this plugin when it comes to the nested inputs.
Essentially there is is a nametemplate and an idtemplate which are the element names only with %index% or %index_phones% where the index should be, and then the name and id which should be these templates only with the %index% or %index_phones% replaced with the actual element input ids.
What happens during the 'normalization' process is that a function runs over these templates (once per element per form), and depending on the form, replaces either %index% or %index_phones% with the relevant index, depending on which form is being processed.
The problem arises when the inputs are nested, as the function first replaces (for instance) %index% with let's say 0. It then updates the resulting name or id with this value, say person_addresses_0_phones_%index_phones%_phone. When it hits the nested form, it then does the same again, only with %index_phones%. The result is now person_addresses_%index%_phones_0_phone because it is still using the unmodified template attribute, rather than the already half-modified name.
To fix this properly, the logic around this whole section of the plugin really needs rebuilding, but I have slapped together a quick patch which should serve as a temporary fix.
In the main plugin file, update the normalizeFieldsForForm function to be:
function normalizeFieldsForForm(form, index)
{
form.find(formFields).each(function(){
var that = $(this)
,idTemplateAttr = getOrSetTemplate(that,"id")
,nameTemplateAttr = getOrSetTemplate(that, "name")
,idAttr = that.attr("id")
,nameAttr = that.attr("name")
,formParents = that.parents('[idtemplate]')
/* Normalize field name attributes */
var newNameAttr = nameTemplateAttr.replace(options.indexFormat, index);
/* Normalize field id attributes */
var newIdAttr = idTemplateAttr.replace(options.indexFormat, index);
$.each(formParents,function(index,element){
$element = $(element);
if($element.data('indexFormat') != options.indexFormat){
/* Normalize field name attributes */
newNameAttr = newNameAttr.replace($element.data('indexFormat'), $element.data('formIndex'))
/* Normalize field id attributes */
newIdAttr = newIdAttr.replace($element.data('indexFormat'), $element.data('formIndex'))
}
});
form.find("label[for='"+idAttr+"']").each(function(){
$(this).attr("for", newIdAttr);
});
that.attr("id", newIdAttr);
that.attr("name", newNameAttr);
});
}
And then update the addForm function. Around line 385 in an unmodified plugin file, add the line
// Index format
newForm.data('indexFormat', options.indexFormat);
above the line
// Index
newForm.data('formIndex', getIndex());
This should serve as a fix until the plugin author gets around to fixing the logic issues. This is for plugin version 1.1.1

fnFilter with multiple values?

I got a table with a column called: "Etiquetas" , there i have multiple tag separated by comma (Ex:"Tag, Tag01, Tag02")
And i have a tag search, where i put all tags,and when you click it, this will be added to the actual search (using fnFilter), the values are passed like: '"Tag", "Tag01"' , but if i filter "Tag" , the filter shows me all rows with that word, instead of the one with the exact word. EX: Show rows with "Tag", and "tag", and "Tag01", etc.
I need help for make exact filter, and with multiples values.
I add a picture to explain this better (i'm bad at explaining things sorry)
Image with the actual problem
You can leverage find and filter for this. While this wont give you a ranked list, like for example items with most tags matched, it will show only items that have at least a matching tag.
This assumes the tags are given as an array, and that etiquettes is.a string of comma separated tags (it could also be an array, but from what I understood, you mentioned separated by comma, so I assume it's a string).
var items = [
{title: "1", etiquettes: "tag01"},
{title: "2", etiquettes: "tag,test"}
];
var tags = ["tag"];
var results = items.filter((item) => {
// splits the tags in the etiquettes, and tries to find at least a matching one. if so, find will return true to the filter function for the current item
return item.etiquettes.split(",").find((itemTag) => {
return tags.indexOf(itemTag) >= 0;
});
});
console.log(results);

SlickGrid: Get the total no of rows after Grouping

I am grouping the slickgrid table, and I want to know the no.of rows after grouping.
I found this solution
grid.getData().getPagingInfo().totalRows
from this question.
But it is not working for the table after grouping.
It returns the total no.of rows of the data not the updated no.of rows after grouping.
Please help me to solve this
Not sure if I understand your question right, but to me it seems that you are confusing Slick objects here. The grid.getData() will return the complete datasource of your grid.
If you take a look at the official SlickGrid example-grouping demo, you will see a grid with grouped set of datas. You can try yourself by opening your favorite browsers Javascript debugger:
dataView.getGroups()
It will return you the corresponding Array of objects from the dataview that contains all groups informations like:
Array [ Object, Object, ... , another 15... ]
You can reach these objects thru specifying the given element key of the returned array:
dataView.getGroups()[0]
Return value of command:
Object {__group: true, level: 0, count: 1, value: 0, title:
"Duration: 0 1, groups: null, groupingKey: "0"}
Now we can see that it has a count property which contains the exact number of rows belong to that group.
So finally by issuing:
dataView.getGroups()[0].count
Will return you:
1
Or by issuing:
dataView.getGroups()[1].count
Will return you:
3
Where both returned count numbers equal with the record numbers you can see in the grid.

Couchdb view to selecting products using another key

I' ve a big list of products (they are ink cartidges and toner) stored in a couchdb, for every document i've got several fields, and one particular field called "models" that is a multidimensional array like this:
"models": {
"Brother": {
"HL": [
"5200",
"5240",
"5240 DN",
"5240 DNLT",
"5240 L",
"5250 DN",
"5250 DNHY",
"5250 DNLT",
"5270 DN",
"5270 DN 2 LT",
"5270 DNLT",
"5280 DW",
"5280 DWLT"
]
},
"": {
"MFC": [
"8460 DN",
"8460 N",
"8860 DN",
"8860 N",
"8870 DW"
],
"DCP": [
"8060",
"8065 DN"
]
},
"Lenovo": {
"": [
"LJ 3500",
"LJ 3550",
"M 7750 N"
]
}
},
I've to do several things with this data, starting with fixing a little problem that i've got while they was written, if you look at the example that i've posted, the second and the third brother serie has an empty array string instead of the "brand" value that should be "Brother"... i've many records that miss the "brand" key for certain series, and this should be set to the previous serie brand, i.e. the "MFC" serie should has the top level key set to "Brother" that is the key of the previous serie.
I can do this using a view in couchdb?
After doing that i need to obtain a list of unique models using another view with every product associated to them.. in other words i've to select all of my products using the last level of the multidimensional array "models" as key (including also brand and serie values as secondary result for futher sorting and filtering) and all the products that contain that certain model as value.
An output like this:
key: "Brother, HL, 5200" - value: "id_product1, id_product2, idproduct3, etc."
Before i start to reading all documentation present on the earth can someone explain me if this thin is at least doable?
Thanks in advance...

Categories

Resources