【问题标题】:Can I append something to object with prime?我可以用素数在对象上附加一些东西吗?
【发布时间】:2018-05-06 08:00:20
【问题描述】:

我可以附加类似的东西

'HI' : {fill : '#000'} 

进入下面的“stateSpecificStyles”?

$('#map').usmap({
            'stateSpecificStyles': {
                'FL' : {fill: '#FFA500'}
            }
        });

结构如下:

var defaults = {
...
// State specific styles. 'ST': {}
    'stateSpecificStyles': {},
...
}

原始文件的 Github 链接是https://github.com/NewSignature/us-map/blob/dev/jquery.usmap.js

【问题讨论】:

    标签: javascript append push add


    【解决方案1】:
      const someSettings = {
         'HI' : {fill : '#000'} 
      };
    
      $('#map').usmap({
            'stateSpecificStyles': {
                'FL' : {fill: '#FFA500'},
                ...someSettings
            }
      });
    

    你可以把它们散布进去。

    【讨论】:

    • 感谢您的回复!但是可以通过使用函数来添加新的东西吗?因为看起来这个 jQuery 插件一旦设置就不能被覆盖,我希望在 for 循环中添加更多东西。
    • @fornowfortest 只需使用$('#map').usmap({ ... })再次挂载它
    • 我想通了。它应该像: $('#map').usmap({ 'stateSpecificStyles': someSettings }});
    • @fornowfortest 那么你应该添加它作为答案:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多