答案 0 :(得分:0)
看看这是否是你想要的
我遵循了我在评论中分享的示例。
let drop = document.getElementById('dropdown');
let canvas = document.getElementById('myCanvas');
let context = canvas.getContext('2d');
let imageObj = new Image();
drop.addEventListener('change', function () {
imageObj.src = this.options[this.selectedIndex].dataset.img;
imageObj.onload = function() {
context.drawImage(imageObj, 69, 50);
};
});
select {
display: block;
}
<select id="dropdown">
<option value='' disabled="disabled" selected="selected">Please Select</option>
<option data-img='https://www.gettyimages.co.uk/gi-resources/images/Embed/new/embed2.jpg'>Option 1</option>
<option data-img='https://www.gettyimages.co.uk/gi-resources/images/Embed/new/embed1.jpg'>Option 2</option>
<option data-img='https://www.gettyimages.co.uk/gi-resources/images/Embed/new/embed3.jpg'>Option 3</option>
</select>
<canvas id="myCanvas" class='background' width="400" height="200" style="border:1px solid #000000;"></canvas>
答案 1 :(得分:0)
main.html
<main>
{{>canvas}}
...
{{>selectValue}}
</main>
<template name='canvas'>
<canvas id="myCanvas" class='background' width="400" height="200" style="border:1px solid #000000;"></canvas>
</template>
<template name='selectValue'>
<select id="dropdown">
<option value='' disabled="disabled" selected="selected">Please Select</option>
{{#each categories}}
<option value="{{this}}">{{this}}</option>
{{/each}}
</select>
</template>
main.js 然后在JS中,您还必须添加
Template.selectValue.helpers({
categories: function () {
return ["Option 1", "Option 2", "Option 3"]
}
});
我认为这是获取数据的正确方向,但是我不确定如何将其显示在画布中。