单击带有参数的吐司(WinJS)导航到特定的 html 页面 [英] Navigate to a specific html page on clicking toasts with params (WinJS)

查看:13
本文介绍了单击带有参数的吐司(WinJS)导航到特定的 html 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WinJS 项目,我收到来自我的网络服务的 toast 通知.在我的网络服务中,我的 XML 就像:

I have a WinJS project and I receive toasts notification from my webservice. In my webservice my XML is like:

 string type = "Computer";
            string toast1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?> ";
            string message = "{\"Message\":{\"Id\":\"6724d22a-87fe-4137-b501-9d9a9a0558b1\",\"DetailId\":\"dc02e784-7832-4625-a538-29be7f885ccb\",\"Description\":\" Message\",\"UserName\":null,\"ActionDateTime\":\"2015-09-15T15:36:14+05:45\",\"CalamityId\":\"c0fa848e-ee6c-4b91-8391-a12058f25387\",\"UseConferenceCalls\":true,\"IsActionCompleted\":false},\"Type\":\"COmp\"}";
          string toast2 = string.Format(@"<toast launch= '{0}'>
                     <visual version='1'>
                         <binding template='ToastText04'>
                             <text id='1'>{1}</text>
                               <text id='2'>{2}</text>
                         </binding>
                     </visual>
                 </toast>", message, "Alert", type);
           string xml = toast1 + toast2;

当用户单击 toast 时,我想导航到特定的 html 页面,并将有用的 json 作为参数.请建议我一些方法来做到这一点.

I want to navigate to a specific html page with the useful json as parameters when user click on toasts. Please suggest me some ways to do this.

目前我已经实现了以下功能来处理我的吐司.这只在应用程序处于活动状态时有效,即在前台或后台运行.但是当应用程序完全关闭时,此功能不会命中并且无法满足我的要求.

Currently I have implemented the following function to handle my toasts.This only works when the app is in active state i.e. running in foreground or background. But when the app is closed completely this function won't hit and failed to meet my requirement.

WinJS.Application.addEventListener("activated", onActivatedHandler, true);

function onActivatedHandler(args) {
    if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
        var messageDetails = (args.detail.arguments).replace(/\\/g, '');
        PhonegapService.setNotificationMessage(messageDetails, function () {
            window.location.href = "page3.html";
        });
    }
}

推荐答案

我遇到了类似的问题.就我而言,我什至在cordova deviceready 被触发之前就调用了函数.根据您的问题,不确定您的应用程序是否为cordova 应用程序,但请确保已加载所有必需的javascript 文件.一旦文档准备好,您就可以执行您的逻辑.我假设您使用的是 jquery.

I was facing a similar issue. In my case I was calling functions even before cordova deviceready was fired. From your question not sure if yours is a cordova app or not but make sure all the required javascript files are loaded. You can execute your logic once document is ready. I assume you are using jquery.

function onActivatedHandler(args) {
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
    $(document).ready(function(){
    var messageDetails = (args.detail.arguments).replace(/\\/g, '');
    PhonegapService.setNotificationMessage(messageDetails, function () {
        window.location.href = "page3.html";
    });
});
}

}

这篇关于单击带有参数的吐司(WinJS)导航到特定的 html 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆