[{"PartnerId":150,"SystemKeyId":1,"KeyId":1,"CategoryID":1,"KeyName":"displayDocumentTypeField","CategoryName":"CategoryType1","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":2,"KeyId":2,"CategoryID":1,"KeyName":"displayAttachmentTypeField","CategoryName":"CategoryType1","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":3,"KeyId":3,"CategoryID":3,"KeyName":"displayFormTypeField","CategoryName":"CategoryType3","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":4,"KeyId":4,"CategoryID":1,"KeyName":"maximumAttachmentFileSize","CategoryName":"CategoryType1","PartnerSupportedValue":"6291456","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":5,"KeyId":5,"CategoryID":2,"KeyName":"UseExternalRealtimeCalls","CategoryName":"CategoryType2","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":6,"KeyId":6,"CategoryID":1,"KeyName":"withdrawalExpiredDays","CategoryName":"CategoryType1","PartnerSupportedValue":"10","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":7,"KeyId":7,"CategoryID":2,"KeyName":"fundTransferExpiredDays","CategoryName":"CategoryType2","PartnerSupportedValue":"5","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":8,"KeyId":8,"CategoryID":2,"KeyName":"serviceFeatureExpiredDays","CategoryName":"CategoryType2","PartnerSupportedValue":"10","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":9,"KeyId":9,"CategoryID":2,"KeyName":"SupportsAttachmentForApplication","CategoryName":"CategoryType2","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":10,"KeyId":10,"CategoryID":3,"KeyName":"SupportsAttachmentForSubpay","CategoryName":"CategoryType3","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":11,"KeyId":11,"CategoryID":3,"KeyName":"rtcEmailNotificationInfo","CategoryName":"CategoryType3","PartnerSupportedValue":"{\"to\" : \"agniswar.das@Ebix.com, amarjeets@ebix.com\", \"from\" : \"AnnuityNet4Notifications@Ebix.com\", \"subject\" : \"Realtime call failure for [PARTNERNAME], [TRANSACTIONID]\", \"body\" : \"Realtime call type [REALTIMECALLTYPE] ([REALTIMECALLGUID]) failed at [DATETIME]. Please contact system administrator.\" , \"enable\" : \"false\" }","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":12,"KeyId":12,"CategoryID":3,"KeyName":"rtcRetryIncludes","CategoryName":"CategoryType3","PartnerSupportedValue":"{\"CurrentTransactionData\":\"5\"}","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":19,"KeyId":19,"CategoryID":1,"KeyName":"SpecialCharAllow","CategoryName":"CategoryType1","PartnerSupportedValue":"^(?!.*(<|>)).*[a-zA-Z0-9 @!#$%^&()_+-={}:;'\\\",.?|\\/~`\\n]+$","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":true,"IsActive":null}]
我有json数据我希望在categoryName的基础上创建它,在每个组之后,我想为jquery嵌套模板创建数组。
categoryList{
categoryName = '',
systemParameter[],
customParameter[]
}
我做了一些更改,但无法获得预期结果,如果可能,请指导我。
var partnerSettingList = function () {
this.categoryName = '';
this.customSettingList = [];
this.systemSettingList = []; };
var partnerSettingCategory = function (result) {
var partnerSettingResults = {};
for (var i = 0; i < result.length; i++) {
var item = result[i];
if (!partnerSettingResults[item.CategoryName]) {
partnerSettingResults[item.CategoryName] = [];
}
partnerSettingResults[item.CategoryName].push({
partnerSettingItem: item
});
}
var partnerSettingCategoryList = [];
for (var x in partnerSettingResults) {
if (partnerSettingResults.hasOwnProperty(x)) {
var obj = {};
obj[x] = partnerSettingResults[x];
partnerSettingCategoryList.push(obj);
}
}
return partnerSettingData(partnerSettingCategoryList) }
提前感谢。
答案 0 :(得分:0)
试试此代码,如果您发现任何问题,请与我们联系。
var data = [{"PartnerId":150,"SystemKeyId":1,"KeyId":1,"CategoryID":1,"KeyName":"displayDocumentTypeField","CategoryName":"CategoryType1","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":2,"KeyId":2,"CategoryID":1,"KeyName":"displayAttachmentTypeField","CategoryName":"CategoryType1","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":3,"KeyId":3,"CategoryID":3,"KeyName":"displayFormTypeField","CategoryName":"CategoryType3","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":4,"KeyId":4,"CategoryID":1,"KeyName":"maximumAttachmentFileSize","CategoryName":"CategoryType1","PartnerSupportedValue":"6291456","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":5,"KeyId":5,"CategoryID":2,"KeyName":"UseExternalRealtimeCalls","CategoryName":"CategoryType2","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":6,"KeyId":6,"CategoryID":1,"KeyName":"withdrawalExpiredDays","CategoryName":"CategoryType1","PartnerSupportedValue":"10","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":7,"KeyId":7,"CategoryID":2,"KeyName":"fundTransferExpiredDays","CategoryName":"CategoryType2","PartnerSupportedValue":"5","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":8,"KeyId":8,"CategoryID":2,"KeyName":"serviceFeatureExpiredDays","CategoryName":"CategoryType2","PartnerSupportedValue":"10","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":9,"KeyId":9,"CategoryID":2,"KeyName":"SupportsAttachmentForApplication","CategoryName":"CategoryType2","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":10,"KeyId":10,"CategoryID":3,"KeyName":"SupportsAttachmentForSubpay","CategoryName":"CategoryType3","PartnerSupportedValue":"False","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":11,"KeyId":11,"CategoryID":3,"KeyName":"rtcEmailNotificationInfo","CategoryName":"CategoryType3","PartnerSupportedValue":"{\"to\" : \"agniswar.das@Ebix.com, amarjeets@ebix.com\", \"from\" : \"AnnuityNet4Notifications@Ebix.com\", \"subject\" : \"Realtime call failure for [PARTNERNAME], [TRANSACTIONID]\", \"body\" : \"Realtime call type [REALTIMECALLTYPE] ([REALTIMECALLGUID]) failed at [DATETIME]. Please contact system administrator.\" , \"enable\" : \"false\" }","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":12,"KeyId":12,"CategoryID":3,"KeyName":"rtcRetryIncludes","CategoryName":"CategoryType3","PartnerSupportedValue":"{\"CurrentTransactionData\":\"5\"}","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":false,"IsActive":null},{"PartnerId":150,"SystemKeyId":19,"KeyId":19,"CategoryID":1,"KeyName":"SpecialCharAllow","CategoryName":"CategoryType1","PartnerSupportedValue":"^(?!.*(<|>)).*[a-zA-Z0-9 @!#$%^&()_+-={}:;'\\\",.?|\\/~`\\n]+$","SystemSuportedValue":"False[False],True[True],Test[Test]","CustomForPartner":true,"IsActive":null}];
var categories = [];
//Creating distinct list of Categories.
$.each(data, function(index, value) {
if ($.inArray(value.CategoryName, categories)==-1) {
categories.push(value.CategoryName);
}
});
console.log(categories);
var finalCollection = [];
//Creating nested collection of categories and related objects.
categories.forEach(function(c){
var result = $.grep(data, function(e){ return e.CategoryName == c; });
finalCollection.push({
CategoryName : c,
Data : result
});
});
console.log(finalCollection);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
&#13;