首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在kendo弹出编辑器上执行javascript

在kendo弹出编辑器上执行javascript
EN

Stack Overflow用户
提问于 2015-11-04 07:20:40
回答 1查看 880关注 0票数 0

我有我的网格和调度程序的弹出编辑器。编辑器由一个kendo模板(MVVM)定义。我想在打开这些编辑器时执行一些javascript,并访问当前正在编辑的模型。我知道执行JS的诀窍,但不知道如何访问模型。

代码语言:javascript
复制
<script id="my-editor" type="text/x-kendo-template" title="Edit Event">
    <div class="k-edit-form-container">
        <input type="hidden" data-bind="value: taskId" />

        <div class="k-edit-label">
            <label for="title">Title</label>
        </div>
        <div data-container-for="title" class="k-edit-field">
            <input type="text" class="k-input k-textbox" name="title" data-bind="value:title">
        </div>

        <div class="k-edit-label">
            <label for="start">Start Date</label>
        </div>
        <div data-container-for="start" class="k-edit-field">
            <input id="eventStartInput" type="text" data-role="datepicker" name="start" data-bind="value:start">
        </div>

        <div class="k-edit-label">
            <label for="currentHatId">Hat</label>
        </div>
        <div id="hatContainer" data-container-for="currentHatId" class="k-edit-field" disabled>
        </div>

    <script>

        jQuery(function(){


            jQuery('<select data-bind="value: currentHatId" name="currentHatId"/>')
                .appendTo(jQuery('#hatContainer'))
                .kendoDropDownList({
                    dataTextField: 'Name',
                    dataValueField: 'HatId',
                    optionLabel: '-- choose hat --',
                    dataSource: { type: 'odata-v4', transport: { read: { url: 'odata/Hats' } } }
                });

            //I want access to the 'bound' model here!
        })
    <\/script>
</script>

做这件事最简单的方法是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-04 15:34:50

在调度程序的编辑事件中,我可以访问正在编辑的模型。因此,我尝试了以下几点:

我将Scheduler配置为创建一个新的ScheduleEditor实例:

代码语言:javascript
复制
edit: (e: kendo.ui.SchedulerEditEvent) => { new ScheduleEditor(e); }

那么我的ScheduleEditor看起来是这样的:

代码语言:javascript
复制
class ScheduleEditor
{
    private _event: kendo.ui.SchedulerEditEvent;

    constructor(e: kendo.ui.SchedulerEditEvent)
    {
        this._event = e;
        e.event.bind('change', (x: any) => { this.eventChanged(x) });
    }

    private eventChanged(x: any)
    {
        console.log('{0} changed', x.field);
    }

    public static initDropDowns(): void
    {
        jQuery('<select data-bind="value: currentHatId" name="currentHatId"/>')
            .appendTo(jQuery('#hatContainer'))
            .kendoDropDownList({
                dataTextField: 'Name',
                dataValueField: 'HatId',
                valuePrimitive: true,
                optionLabel: '-- choose hat --',
                dataSource: { type: 'odata-v4', transport: { read: { url: 'odata/Hats' } } }
            });
    }
}

注意valuePrimitive = true,因为这对我来说是个问题。

从构造函数调用initDropdowns()没有初始化下拉列表以纠正值,因此从模板调用它:

代码语言:javascript
复制
    </div>
</div>
<script>

    jQuery(function(){
        ScheduledRecipeEditor.initDropDowns();
    })
<\/script>

现在,在我的ScheduleEditor实例中,我可以对模型中的更改做出反应。希望这能帮上忙。对于网格上的弹出编辑器来说也应该是一样的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33515905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档