Kendo UI TreeView dataTextField 和 model.fields.text.from 之间的

Kendo UI TreeView difference between dataTextField and model.fields.text.from

本文关键字:text from 之间 fields model UI TreeView dataTextField Kendo      更新时间:2023-09-26

我有一个分层数据源,其中节点的文本由title字段提供。树视图希望该字段text。有两种方法可以进行该映射:

  1. dataTextField : 'title'传递给treeview构造函数
  2. 传递 schema.model: fields.text.from ,其中"指定原始记录的字段,该值用于模型字段的填充",即 schema: { model: { fields: { text: { from: 'title' } },... }

除了文档中的语法错误options.fields,我应该选择哪种方法?

使用 dataTextField 选项可以通过数据中的原始名称引用节点的属性,在本例中title

var myHDS = new kendo.data.HierarchicalDataSource({
    transport: {
        read: function (options) {
            var node = myHDS.get(options.data.id);
            // node.title is accessible here
        }
    },
    schema: {
        model: {
            id: 'id',
            hasChildren: 'children'
        }
    }
});
$("#tree-container").kendoTreeView({
    dataSource: myHDS,
    dataTextField: 'title'
})

schema.model.fields.text.from设置为 title 将需要您将节点的 title 属性引用为 node.text

var myHDS = new kendo.data.HierarchicalDataSource({
    transport: {
        read: function (options) {
            var node = myHDS.get(options.data.id);
            // node.title is accessible here
        }
    },
    schema: {
        model: {
            fields: {
                text: {
                    from: 'title'
                }
            },
            id: 'id',
            hasChildren: 'children'
        }
    }
});
$("#tree-container").kendoTreeView({
    dataSource: myHDS
})