Mercury - 如何设置选项元素的 'selected' 属性?

Mercury - How do I set an option element's 'selected' property?

如何设置selected property of an option element with Mercury/virtual-dom

我试过以下方法,但 selected 属性 没有出现在 <option> 上:

h('select', {
  name: 'selectedRole', 
}, [
  h('option', {value: 'user', selected: true}, 'User'),
])

相反,结果是:

<select name="selectedRole">
  <option value="user">User</option>
</select>

经过一些测试,这似乎是 Mercury 的工作方式。当您在 option 上将 selected 设置为 true 时,即使 属性 在 HTML 元素上不可见,它也会被选中。

但是,我只能让它在一个小的演示中工作,而不是在我的完整应用程序中。因此,virtual-dom.

中可能存在错误
    $("option[value='user']").attr('selected', true);

我也遇到过 html5 数据列表标签的列表属性的问题。 一种解决方法是使用 javascript 或 jquery 来动态分配此属性。