Ich habe dieses Array:Underscore.js - Gruppenobjekte von Eigentum und ausdrucken
var ty = [
{
"Language": "en-GB",
"Section": "Sales",
"ItemName": "Type",
"Texts": "Having selected the account heading select the calculation ..."
},
{
"Language": "en-GB",
"Section": "Sales",
"ItemName": "Try",
"Texts": "This is not happenning tho ..."
},
{
"Language": "en-GB",
"Section": "Taxes",
"ItemName": "Save",
"Texts": "The Master Tax Table has been pre populated with the current UK, ..."
}];
und ich brauche es in einer Art und Weise zu einer Gruppe, die den Abschnitt nach ihm alle Eigenschaften enthält, die den gleichen Abschnitt haben, wie folgt:
[
{section: 'Sales', ItemName: ['Type', 'Try'] Texts: ["Having selected the account heading select the calculation ...", "This is not happenning tho."]},
{section: 'Taxes', ItemName: ['Type'] Texts: ['Having selected the account heading select the calculation.']}
]
So, wenn ich es drucke, wird es nur den Text jedes Abschnitts drucken.
Dies ist der Code, den ich bisher habe:
var log = function(contents) {
if (_.isArray(contents)) {
_.each(contents, function(e, i, l) {
log(e);
$('#result');
$('#result').append('</br></br>');
});
} else {
console.log(contents);
$('#result').append(contents);
}
};
var ty = [
{
"Language": "en-GB",
"Section": "Sales",
"ItemName": "Type",
"Texts": "Having selected the account heading select the calculation ..."
},
{
"Language": "en-GB",
"Section": "Sales",
"ItemName": "Try",
"Texts": "This is not happenning tho ..."
},
{
"Language": "en-GB",
"Section": "Taxes",
"ItemName": "Save",
"Texts": "The Master Tax Table has been pre populated with the current UK, ..."
}];
var out = [];
_.groupBy(ty.Section, function(item){
section: item.Section
_.each(ty, function(item) {
var hold = {};
hold.options = {};
hold.options.section[item.ItemName] = {
text: item.Texts,
};
out.push(hold)
});
});
log(out);
ich versucht habe:
//More code above
_.each(ty, function(item) {
iName: item.itemName;
var hold = {};
hold.options = {};
hold.options.section.iName = {
text: item.Texts,
};
out.push(hold)
aber noch wird es nichts drucken. In meinen Entwicklungswerkzeugen zeigt es nichts.
irgendwelche Tipps?
es muss mit Strich erfolgen:/ – noel293
@GeorgeXReplay. Ich habe eine Unterstreichungsversion meines Javascript-Codes hinzugefügt. –