我继承了一个项目,需要以这种格式(动态)重新创建一个对象,但不知道该怎么做。这就是我尝试过的,它几乎就在那里:
//this creates [{ "Country": ["Canada", "United States of America"] }]
filters = [];
var object = {};
object.Country = [];
object.Country.push('Canada', 'United States of America');
filters.push(object);
//alert(JSON.stringify(filters));
console.log(JSON.stringify(filters));
//currently getting this
//filters = [{ "Country": ["Canada", "United States of America"] }]
//need this
//filters = { 'Country': ['Canada', 'United States of America'] };
我有一个表单,用户将在表格(国家/地区)中选择列,然后输入一个或多个国家/地区。目前,过滤器基于上面的硬编码对象工作。我现在需要动态更改其他列的对象。
非常感谢任何帮助。