public HostJsView() { _context = new HostViewContext(); _context.RootPath = GlobalCommon.HostCommon.RootPath; _context.RunTimeLibPath = GlobalCommon.HostCommon.RootPath + HostJsConstants.COMPILED_ROOT_PATH; _context.CommonLibPath = GlobalCommon.HostCommon.RootPath; }
/// <summary> /// 根据指定的上下文结构执行View渲染 /// </summary> /// <param name="js"></param> /// <param name="context"></param> /// <returns></returns> public string Render(string js, HostViewContext context) { var rtn = ""; try { var l = context.AllHostJsObject; List <KeyValuePair <string, object> > kvp = new List <KeyValuePair <string, object> >(); foreach (var item in l) { if (item.Name.ToLower() != "model") { kvp.Add(new KeyValuePair <string, object>(item.Name, item)); } } kvp.Add(new KeyValuePair <string, object>("model", context.CurrentModel)); context.CurrentHostJsEngine.Evaluate(js, kvp.ToArray()); rtn = ((ViewDocument)context.GetHostJsObject("viewdoc")).OutHtml(); } finally { context.CurrentHostJsEngine.Release(); } return(rtn); }
/// <summary> /// Debug方式运行js,该方式不会自动释放js引擎资源,需要手动执行,如果js引擎资源得不到良好释放会导致系统无法运行 /// </summary> /// <param name="js"></param> /// <param name="context"></param> /// <param name="outobjname"></param> /// <returns></returns> public object DebugRun(string js, HostViewContext context, string outobjname) { Dictionary <string, object> dic = new Dictionary <string, object>(); foreach (var item in context.AllHostJsObject) { dic.Add(item.Name, item); } context.CurrentHostJsEngine.Evaluate(js, dic.ToArray()); var outobj = context.CurrentHostJsEngine.GetOutObject(outobjname); if (outobj == null) { outobj = FrameDLRObject.CreateInstance(); } if (outobj is Dictionary <string, object> ) { return(FrameDLRObject.CreateInstance(outobj, FrameDLRFlags.SensitiveCase)); } else { return(outobj); } }
public HostJsView(HostViewContext context) { _context = context; }
/// <summary> /// Debug模式运行,需要人工释放js引擎资源 /// </summary> /// <param name="js"></param> /// <param name="context"></param> /// <returns></returns> public object DebugRun(string js, HostViewContext context) { return(DebugRun(js, context, "out")); }