It's having a type inference failure on the `item`...
# tornadofx
s
It's having a type inference failure on the
item
from what I can gather from the error because menu items extend Object not Node, I believe.
n
I don't know if this is the best way - but it seams to work:
Copy code
import javafx.beans.property.SimpleStringProperty
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.scene.control.MenuItem
import tornadofx.*

class TestApp : App(TestView::class)

class TestView : View() {
    val model: ObservableList<Model> = FXCollections.observableArrayList()
    var counter = 1
    override val root = vbox {
        menubar {
            menu("menu") {
                item("add").action { println("add"); model.add(Model().apply { name.value = "test${counter++}" }) }
                item("rem first").action { println("rem"); model.removeAt(0) }
                val map = HashMap<Model, MenuItem>()
                model.onChange { change ->
                    change.next()
                    for (elem in change.addedSubList) {
                        map[elem] = MenuItem(elem.name.value).apply { action { println(elem.name.value) } }
                        items.add(map[elem])
                    }
                    for (elem in change.removed) {
                        items.remove(map[elem])
                        map.remove(elem)
                    }
                }
            }
        }
    }
}

class Model {
    val name = SimpleStringProperty()
}