我有一个可观察的数组
var items= [
{"image": "/images/image1.jpg" },
{"image": "/images/image2.jpg" },
{"image": "/images/image3.jpg" }
];
我的模板如下所示:
<div data-bind="foreach: items">
<div class="box" data-bind="style: {'background-image': url(image)}"></div>
</div>
不幸的是,这不起作用。我想要的是这样的:
<div>
<div class="box" style="background-image: url(/images/image1.jpg)"></div>
<div class="box" style="background-image: url(/images/image2.jpg)"></div>
<div class="box" style="background-image: url(/images/image3.jpg)"></div>
</div>
我怎样才能做到这一点?