File size: 739 Bytes
630cbf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(props, cc, { el, onMount }) => {
  const options = JSON.parse(props.options);
  el.innerHTML = `
  ${options
    .map((option) => {
      return `<div>
        <label>${option} <input type="radio"/></label>
    <div>`;
    })
    .join('')}
  `;
  onMount(() => {
    const inputs = Array.from(el.getElementsByTagName('input'));
    Array.from(el.getElementsByTagName('label')).forEach((label, i) => {
      label.addEventListener('click', () => {
        inputs.forEach((input) => {
          input.checked = false;
        });
        const input = label.getElementsByTagName('input')[0];
        input.checked = true;
        // 通过 cc.dispatch 向 python 侧发送通知
        cc.dispatch(options[i]);
      });
    });
  });
};