我试图简单地用市场列表填充多选字段。
这是市场对象:
var marketplaces = {
amazonCom:{
label: 'Amazon.com',
searchId: 'customsearch_ca_export_detail_search__21',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_us'
},
amazonUK:{
label: 'Amazon.uk',
searchId: 'customsearch_ca_export_detail_search__33',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_uk'
},
amazonCA:{
label: 'Amazon.ca',
searchId: 'customsearch_ca_export_detail_search__23',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_ca'
},
amazonFR:{
label: 'Amazon.fr',
searchId: 'customsearch_ca_export_detail_search__26',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_fr'
},
amazonDE:{
label: 'Amazon.de',
searchId: 'customsearch_ca_export_detail_search__24',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_de'
},
amazonIT:{
label: 'Amazon.it',
searchId: 'customsearch_ca_export_detail_search__29',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_it'
},
amazonJP:{
label: 'Amazon.co.jp',
searchId: 'customsearch_ca_export_detail_search__30',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_jp'
},
amazonES:{
label: 'Amazon.es',
searchId: 'customsearch_ca_export_detail_search__37',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_es'
},
ebayCom:{
label: 'eBay.com',
searchId: 'customsearch_ca_export_detail_search__34',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_us2'
},
ebayUk:{
label: 'eBay.uk',
searchId: 'customsearch_ca_export_detail_search__51',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_uk2'
},
ebayAu:{
label: 'Amazon.au',
searchId: 'customsearch_ca_export_detail_search__50',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_au'
},
ebayVolt:{
label: 'eBay.com Volt',
searchId: 'customsearch_ca_export_detail_search__35',
scriptId: 'customscript_revant_ca_catalog_export',
deploymentId: 'customdeploy_revant_ca_catalog_volt'
}
};
我正在尝试按照文档填充多选字段。这是代码:
var marketplacesList = form.addField({
id:'selectedmarketplaces',
type:ui.FieldType.MULTISELECT,
label:'Marketplaces'
});
for (var i = 0; i<marketplaces.length; i++){
marketplacesList.addSelectOption({
value: marketplaces[i].label,
text: marketplaces[i].label
});
}
任何帮助?
谢谢,
答案 0 :(得分:1)
您的问题是marketplaces
不是数组,因此它没有length
属性。
尝试用以下代码替换for行:
for (var i in marketplaces) {
if(!marketplaces.hasOwnProperty(i)) {
continue;
}
// Add option for form or whatever...
}