首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含有唯一ID的用户控件的分层网格

包含有唯一ID的用户控件的分层网格
EN

Stack Overflow用户
提问于 2016-09-02 10:56:00
回答 1查看 43关注 0票数 1

我有一个嵌套的Kendo Grid,它包含一个TabStrip控件,该控件包含从初始div元素生成的多个kendoComboBox

网格在Javascript中生成:

代码语言:javascript
复制
$("#configAddGrid").kendoGrid({
        dataSource: gridConfigDataSourceAdd,
        height: 550,
        detailTemplate: kendo.template($("#templateAdd").html()),
        detailInit: detailAddInit,
        navigatable: true,
        autoBind: false,
        editable: {
            mode: "incell"
        },
        toolbar: ["create"],
        columns: columnSchemaAdd
    });

下面定义了kendo-templateTabStrip是使用每行的ID字段唯一标识的:

代码语言:javascript
复制
@(Html.Kendo().TabStrip()
        .Name("tabStripAdd_#=ID#")
        .SelectedIndex(0)
        .Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
        .Items(items =>
        {
                items.Add().Text((string)ViewBag.ControlSetLots[0].LotNumber).Content(@<text>

                    <p>StandardComment: </p>
                    <div id='Lot1StandardCommentDropDownAdd_#=ID#' class='Lot1StandardCommentDropDownAdd'>    
                    </div> 
                    <p>Review Comment: </p>
                    <div id='Lot1ReviewCommentDropDownAdd_#=ID#' class='Lot1ReviewCommentDropDownAdd'>        
                    </div>

                   </text>
                );
            }...

我的计划是通过ComboBox函数初始化每个Kendo ComboBox,也就是说,一旦发送了扩展行的请求。ComboBox的创建将基于div的唯一ID。但是,分配给divdiv在使用检查器窗口(emptyID.png)检查时是空的,即使它被附加到TabStrip控件中。

代码语言:javascript
复制
function detailAddInit(e) {
    var closestCB = e.detailRow.find('.Lot1StandardCommentDropDownAdd');        

    createStandardCommentDropDown("#Lot1StandardCommentDropDownAdd");
    createReviewCommentDropDown("#Lot1ReviewCommentDropDownAdd");            
    kendo.bind(e.detailRow, e.data);
}

有什么方法可以将相同的ID附加到我的div的末尾,使它成为唯一的?

此外,如果有人能想出一个更好的方法来实现同样的结果,请随时评论,因为我是开放的建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-02 15:58:46

我找到了一个解决方案,以确保每个ComboBox都分配一个唯一的ID。

1)删除了在ID中分配的cshtml

代码语言:javascript
复制
@(Html.Kendo().TabStrip()
        .Name("tabStripEdit_#=ID#")
        .SelectedIndex(0)
        .Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
        .Items(items =>
        {                
            items.Add().Text((string)ViewBag.ControlSetLots[0].LotNumber).Content(@<text>

                <p>Standard Comment: </p>
                <div class='Lot1StandardCommentDropDownEdit'>
                </div>
                <p>Review Comment: </p>
                <div class='Lot1ReviewCommentDropDownEdit'>
                </div>

                </text>
            );
        }

2)修改了detailAddInit(e)函数,使用从Grid请求嵌套detailTemplate的当前时间分配惟一的detailTemplate ID

代码语言:javascript
复制
function detailAddInit(e) {
    var time = new Date().getTime().toString();
    // find combo box associated with current row
    var closestSCCB = e.detailRow.find('.Lot1StandardCommentDropDownAdd');            
    // assign a unique ID to the div
    var SCID = 'Lot1StandardCommentDropDownAdd_' + time;
    closestSCCB.attr('id', SCID);
    var closestSCCB2 = e.detailRow.find('.Lot1StandardCommentDropDownAdd');            

    var closestRCCB = e.detailRow.find('.Lot1ReviewCommentDropDownAdd');
    var RCID = 'Lot1ReviewCommentDropDownAdd_' + time;
    closestRCCB.attr('id', RCID);
    var closestRCCB2 = e.detailRow.find('.Lot1ReviewCommentDropDownAdd');

    createStandardCommentDropDown(closestSCCB2[0]);
    createReviewCommentDropDown(closestRCCB2[0]);   
}

虽然这是我的利基场景,但我希望这能使未来的某一天!

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

https://stackoverflow.com/questions/39290692

复制
相关文章

相似问题

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