Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
153 views
in Technique[技术] by (71.8m points)

javascript - Debugging an ASP.NET MVC Kendo TabStrip

I've got a Kendo TabStrip

@(Html.Kendo().TabStrip()
    .Name("tabstrip")
    .Events(e => e.Select("onTabSelect"))
    .Items(tabstrip =>
    {
        tabstrip.Add().Text("Tab 1")
            .Selected(true)
            .Content(@<text>
                <div class="panel-heading">
                    <h3 class="panel-title">Tab 1</h3>
                </div>
            </text>);
        tabstrip.Add().Text("Tab 2")
            .Content(@<text>
                <div class="panel-heading">
                    <h3 class="panel-title">Tab 2</h3>
                </div>
            </text>);
        tabstrip.Add().Text("Tab 3")
            .Content(@<text>
                <div class="panel-heading">
                    <h3 class="panel-title">Tab 3</h3>
                </div>
            </text>);
        tabstrip.Add().Text("Tab 4")
            .Content(@<text>
                <div class="panel-heading">
                    <h3 class="panel-title">Tab 4</h3>
                </div>
            </text>);
    })
)

The jQuery below fires whenever one of the tabs is selected:

function onTabSelect(e) {
    var tab = $(e.item).find("> k-link");
    if (tab !== null) {
        console.log(tab);
        var tabText = tab.text();
        console.log(tabText);
        if (tabText == "Tab 1") {
            // 
        } else if (tabText == "Tab 2") {
            alert('Tab 2');
        } else if (tabText == "Tab 3") {
            alert('Tab 3');
        } else if (tabText == "Tab 4") {
            alert('Tab 4');
        }
    }
};

The alert() boxes are not being called, so I am debugging this in the Chrome debugger using the two (2) console.log messages.

There are four (4) console writelines shown below from me selecting "Tab 2" and then "Tab 3". The first has data (expanded for the screenshot), the second has nothing, the third has data, and the fourth has nothing:

screenshot of both

The first console.log message contains everything I need, but I don't know how to get it.

The second console.log shows my attempt to read the text using var tabText = tab.text(); but it comes back as null.

I don't know how to copy and paste the whole text, but the first message can be expanded to show the context: li.k-item.k-state-default and a long list of properties under it.

screenshot of li.k-item

If I could scroll down far enough, you would see that I have the innerText item set to what I need to read in.

I tried digging into the context using this:

function onTabSelect(e) {
    var tab = $(e.item).find("> k-link");
    if (tab !== null) {
        console.log(tab);
        var context = tab.context;
        console.log(context);
        var contextText = context.text;
        console.log('context text = ' + contextText);
        var tabText = tab.text();
        console.log('tabText = ' + tabText);

The extra logging above outputs this:

extra logging screen

I can see "Tab 2" shown in the context item, but how do I read it in jQuery?

question from:https://stackoverflow.com/questions/65853170/debugging-an-asp-net-mvc-kendo-tabstrip

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...