- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个名为 requestStruct 的结构,如下所示:
{"api_version":"1","SourceId":"99","CampaignId":"999","policy":{"zip":"60644","street_address":"43 Memory Lane","email":"test@test.com","currently_insured":"true","coverage_level":"2","current_carrier":"28","current_insured_duration":"7"},"drivers":[{"first_name":"Bat","last_name":"Man","birth_date":"1966-07-07","homeowner":"true","sr22":"false"},{"first_name":"Boy","last_name":"Wonder","birth_date":"1966-07-07","homeowner":"true","sr22":"false"},{"first_name":"Cat","last_name":"Woman","birth_date":"1966-06-06","homeowner":"true","sr22":"false"},{"first_name":"Bat","last_name":"Girl","birth_date":"1966-01-01","homeowner":"true","sr22":"false"}]}
<cfscript>
metadata = {
api_version: {type:"string",name:"api_version"},
SourceId: {type:"string",name:"SourceId"},
CampaignId: {type:"string",name:"CampaignId"}
};
StructSetMetaData(requestStruct,metadata);
</cfscript>
<cfscript>
metadata = {
policy:{
keys:{
"zip":{type:"string",name:"zip"},
"email":{type:"string",name:"email"},
"currently_insured":{type:"string",name:"currently_insured"},
"coverage_level":{type:"string",name:"coverage_level"},
"current_carrier":{type:"string",name:"current_carrier"},
"current_insured_duration":{type:"string",name:"current_insured_duration"}
}
}
};
StructSetMetaData(requestStruct,metadata);
</cfscript>
但是我无法弄清楚如何对结构的驱动程序部分执行相同的操作,因为它包含一个数组。
<cfscript>
metadata = {
drivers:{
keys:{
"homeowner":{type:"string",name:"homeowner"},
"sr22":{type:"string",name:"sr22"}
}
}
};
StructSetMetaData(requestStruct,metadata);
</cfscript>
我试过这个,但没有效果:
<cfscript>
metadata = {
drivers:{
keys:{
"homeowner[0]":{type:"string",name:"homeowner"},
"sr22[0]":{type:"string",name:"sr22"}
}
}
};
StructSetMetaData(requestStruct,metadata);
</cfscript>
如何为驱动程序 key 中结构数组中的 key 设置元数据?
最佳答案
我会做这样的事情。对于数组内部结构,您需要以与为 arraySetMetaData 提供元数据相同的方式提供元数据。功能。
<cfset requestStruct = {"api_version":"1","SourceId":"99","CampaignId":"999","policy":{"zip":"60644","street_address":"43 Memory Lane","email":"test@test.com","currently_insured":"true","coverage_level":"2","current_carrier":"28","current_insured_duration":"7"},"drivers":[{"first_name":"Bat","last_name":"Man","birth_date":"1966-07-07","homeowner":"true","sr22":"false"},{"first_name":"Boy","last_name":"Wonder","birth_date":"1966-07-07","homeowner":"true","sr22":"false"},{"first_name":"Cat","last_name":"Woman","birth_date":"1966-06-06","homeowner":"true","sr22":"false"},{"first_name":"Bat","last_name":"Girl","birth_date":"1966-01-01","homeowner":"true","sr22":"false"}]}>
<cfscript>
metadata = {
api_version: {type:"string",name:"api_version"},
SourceId: {type:"string",name:"SourceId"},
CampaignId: {type:"string",name:"CampaignId"},
policy:{
keys:{
"zip":{type:"string",name:"zip"},
"email":{type:"string",name:"email"},
"currently_insured":{type:"string",name:"currently_insured"},
"coverage_level":{type:"string",name:"coverage_level"},
"current_carrier":{type:"string",name:"current_carrier"},
"current_insured_duration":{type:"string",name:"current_insured_duration"}
}
}
};
driversMetadata = {
items: []
};
for(driver in requestStruct.drivers){
driversMetadata.items.append({
"homeowner":{type:"string", name:"homeowner"},
"sr22":{type:"string", name:"sr22"}
});
}
metadata.drivers = driversMetadata;
StructSetMetaData(requestStruct, metadata);
</cfscript>
DEMO
关于Coldfusion StructSetMetaData 不更新结构内数组中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67626106/
我有一个名为 requestStruct 的结构,如下所示: {"api_version":"1","SourceId":"99","CampaignId":"999","policy":{"zip"
我是一名优秀的程序员,十分优秀!