I am trying to create a note that obtains a filtered dataview from the selected value of the combo and updates it. I don’t know if what I’m doing is correct. Can you help me?
This is the code in my note:
<select id="mySelect" onchange="updateDataView()">
<option value="computer">computer</option>
<option value="house">house</option>
<option value="keyboard">keyboard</option>
</select>
<script>
function updateDataView() { var combo = document.getElementById("mySelect"); var selectedOption = combo.options[combo.selectedIndex].value; var dataViewCode = "```myDataView\n" + "table from #Enlaces where contains(topics, \"" + selectedOption + "\")\n" + "```";
// Actualizamos el contenido del DataView en el editor de texto
var editor = document.querySelector('.CodeMirror').CodeMirror; var currentText = editor.getValue(); var newText = currentText.replace(/```dataview myDataView[\s\S]*?```/, dataViewCode); editor.setValue(newText);
// Forzamos a Obsidian a renderizar la nota nuevamente
var event = new Event('input', { bubbles: true, cancelable: true, }); editor.getInputField().dispatchEvent(event); }
</script>
```dataview myDataView
table from #Links where contains(topics, "computer")
Thank you.