将事件添加到Lightswitch HTML客户端中的选项卡选择

时间:2014-04-28 13:40:58

标签: lightswitch-2013

使用Lightwitch 2013 HTML客户端。 我试图添加一个事件,当选择(或点击)屏幕上的选项卡时将触发该事件。 我没有得到以下代码的任何结果: -

myapp.ViewThing.HistoryTab_postRender = function (element, contentItem) {
    $(element).click(function () { alert("clicked on tab !!!"); });
    $(element).select(function () { alert("selected tab !!!"); });
};

以上是屏幕上标签的后期呈现代码。 相同类型的代码适用于其他屏幕对象,例如文本字段。

知道我做错了什么,或者为什么这对标签不起作用?

谢谢!

2 个答案:

答案 0 :(得分:0)

你可以使用jQuery挂钩选项卡容器上的相应监听器(在任何postRender事件中每个屏幕一次)并只处理当前激活的选项卡

myapp.ViewThing.HistoryTab_postRender = function (element, contentItem) {
    $(".msls-tabs-container li").on("click", function (e) {
        $.each(contentItem.screen.details.pages, function () {
            if (this.___isActivated) {
                // use 'this'
            };
        });
    });
};

另一种可能性是使用

在DOM树中搜索最接近的相应div
myapp.ViewThing.HistoryTab_postRender = function (element, contentItem) {
    $(element).closest("div[data-role='page']").find(".msls-tabs-container li").click(function (e) {
        // use $(this)
    });
};

答案 1 :(得分:0)

在创建的函数

中尝试此操作
  $($.mobile.activePage
.find(".msls-screen-tab")[4]).on("click", function (e) {
    //Do something.
});
}, 0);

[4]是Tab键顺序,从第一个选项卡的[0]开始。

此致 斯文

相关问题