【问题标题】:Passing a JSON object from visualwebgui to a htmlbox html page?将 JSON 对象从 visualwebgui 传递到 htmlbox html 页面?
【发布时间】:2013-08-01 09:48:02
【问题描述】:

我有一种情况,我正在使用 Gizmox VWG 6.4 和一个 HTML 页面来显示一些 D3js 可视化。

目前我正在生成没有问题的数据。最终结果是我的 D3js 应用程序具有正确格式的 JSON 对象。我需要做的是以某种方式在 Gizmox VWG 中托管 HTML(可能是通过 HtmlBox??),然后以某种方式使 JSON 对象可用于 HtmlBox,以便 HTML/JS 应用程序可以读取它?理想情况下不必将 JSON 存储在磁盘上?

如果这可能的话,有什么想法吗??

谢谢。

【问题讨论】:

    标签: json d3.js visual-web-gui


    【解决方案1】:

    当然,这可以使用 Visual WebGUI 网关来提供 HtmlBox。假设您有一个带有 HtmlBox 的表单,您可以执行以下操作:

    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Web;
    
    using Gizmox.WebGUI.Common;
    using Gizmox.WebGUI.Common.Gateways;
    using Gizmox.WebGUI.Forms;
    
    namespace VisualWebGuiApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                NameValueCollection NVC = new NameValueCollection();
                NVC.Add("JsonParm1", "value1");
                NVC.Add("JsonParm2", "value2");
                this.htmlBox1.Url = (new GatewayReference(this, "generateJSON", NVC)).ToString();
            }
    
            protected override Gizmox.WebGUI.Common.Interfaces.IGatewayHandler ProcessGatewayRequest(Gizmox.WebGUI.Hosting.HostContext objHostContext, string strAction)
            {
                if (strAction == "generateJSON")
                {
                    // make sure no caching takes place.
                    objHostContext.Response.Expires = -1;
                    objHostContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    objHostContext.Response.CacheControl = "no-cache";
                    objHostContext.Response.AddHeader("Pragma", "no-cache");
    
                    // Get the parameters from the gateway reference
                    string strParm1 = objHostContext.Request["JsonParm1"].ToString();
                    string strParm2 = objHostContext.Request["JsonParm2"].ToString();
    
                    // build your output and set content type
                    objHostContext.Response.ContentType = "text/html";
                    objHostContext.Response.Write("the data you want to write");
    
                    objHostContext.Response.Flush();
                    return null;
                }
                else 
                    return base.ProcessGatewayRequest(objHostContext, strAction);
            }
        }
    
    }
    

    网关实际上是 VWG 的一个非常强大的功能。见Here

    希望这会有所帮助, 帕利

    【讨论】:

    • 嘿,谢谢 Pali,这看起来是个不错的选择!对 VWG 的更高级部分来说还是有点新,但是我确实“破解”了一个网关选项来自动下载 csv 文件。只是没有为这种类型的请求建立连接。事实上,我的“糟糕”解决方案是: this.htmlBox1.InvokeClientMethod("tfrJSON", JSONdata);它将 JSON 数据传递给一个名为 tfrJSON 的 JS 函数——在我的情况下,还不错,因为 JSON 很小。但是肯定会尝试您的解决方案!再次感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 2014-03-22
    • 2022-01-19
    • 1970-01-01
    相关资源
    最近更新 更多