我正在使用下面的代码将内容插入页面。我需要在文本中插入一些变量来生成一些动态值,并且不确定如何执行此操作。有人能告诉我需要改变什么吗?
下面是我在JS中存储数据的精简示例:
var fruit = {
'apples': {
'goldenDelicious' : {
color: 'yellow',
sale: 'A sale of $XXXXX (need to insert a number in here). Be sure to buy some before they are all gone!',
link: {
linkText: ('This company sells this for $XXXXX (eed to insert a price here). Click here to visit their site.'),
url: 'I NEED TO INSERT THE URL HERE'
}
}
}
}
下面是一个我如何称呼它的例子:(它比这个更具活力,但你知道这个想法)
var fruitType = 'apples';
var fruitVariety = 'goldenDelicious';
fruit[fruitType][fruitVariety], function () {
// do something
});
所以我希望能够在对象中插入价格、销售和URL等值。