我正在使用 Kendo UI Grid,并且已将其配置为使用带有自定义模板的弹出编辑
    <script id="popup_editor" type="text/x-kendo-template">
    <div id="editor">
            <div class="k-edit-label">
                <label for="Type">Type</label>
            </div>
    <select data-role="dropdownlist" data-value-field="Type" data-text-field="Type"
                         data-bind="source: typeSource, value: selectedProduct"></select>
<div class="k-edit-label">
                <label for="Type">Option</label>
            </div>
<select data-role="dropdownlist" data-value-field="Option" data-text-field="Option"
                         data-bind="source: productsSource.Options, value: selectedOption"></select>
            </div>
</script>
这是我的视图模型:
    function ViewModel() {
        var getTypesUrl = "/Controller/Action";
        var viewModel = kendo.observable({
            typeSource: new kendo.data.DataSource({
                transport: {
                    read: {
                        url: getConditionTypesUrl,
                        dataType: "json"
                    },
                },
                batch: true,
                schema: {
                    model: {
                        id: "Type"
                    }
                }
            }),
            selectedType: null,
            selectedOption: null
        });
        kendo.bind($("#editor"), viewModel);
    }
ViewModel();
我的操作返回 JSON。
问题是当我点击“添加新记录”按钮时,没有调用getTypesUrl并且下拉列表没有填充。一般的想法是为不同的类型提供不同的选项,并根据所选类型填充选项下拉列表。我相信,之所以会出现问题,是因为仅在单击按钮时才显示编辑器并且剑道无法创建绑定。