是否必须将Redux与React-Native一起使用?(Is it mandatory to use Redux with React-Native?)
一段时间以来,我正在学习React-native。 我发现redux非常令人困惑。 当我来自Java和Angular背景时,这是一种完全不同的思考应用程序结构的方式。 无论如何我想知道是否必须只使用反应原生的Redux? 或者是否也可以使用一些更接近MVC模式的其他框架。
For some time now, I am learning React-native. I find redux very confusing. It's a completely different way of thinking about your application structure as I come from Java and Angular background. Any way I was wondering if it is mandatory to use Redux only with react-native? or is it also possible to use some other framework, which is more close to the MVC pattern.
原文:https://stackoverflow.com/questions/41206773
最满意答案
我看了一下MVC的源码,看看我能否找出如何做到这一点。 控制器上下文,视图,视图数据,路由数据和html渲染方法之间似乎有很紧密的耦合。
基本上为了实现这一点,您需要创建所有这些额外的元素。 其中一些是相对简单的(如视图数据),但有些更复杂 - 例如,路由数据将考虑当前WebForms页面被忽略。
大问题似乎是HttpContext - MVC页面依赖于HttpContextBase(而不是像WebForms这样的HttpContext),并且同时实现IServiceProvider它们不相关。 MVC的设计者作出了一个故意的决定,不会改变传统的WebForms来使用新的上下文基础,但是它们提供了一个包装器。
这可以让您将部分视图添加到WebForm中:
public class WebFormController : Controller { } public static class WebFormMVCUtil { public static void RenderPartial( string partialName, object model ) { //get a wrapper for the legacy WebForm context var httpCtx = new HttpContextWrapper( System.Web.HttpContext.Current ); //create a mock route that points to the empty controller var rt = new RouteData(); rt.Values.Add( "controller", "WebFormController" ); //create a controller context for the route and http context var ctx = new ControllerContext( new RequestContext( httpCtx, rt ), new WebFormController() ); //find the partial view using the viewengine var view = ViewEngines.Engines.FindPartialView( ctx, partialName ).View; //create a view context and assign the model var vctx = new ViewContext( ctx, view, new ViewDataDictionary { Model = model }, new TempDataDictionary() ); //render the partial view view.Render( vctx, System.Web.HttpContext.Current.Response.Output ); } }
然后在您的WebForm中,您可以这样做:
<% WebFormMVCUtil.RenderPartial( "ViewName", this.GetModel() ); %>
I had a look at the MVC source to see if I could figure out how to do this. There seems to be very close coupling between controller context, views, view data, routing data and the html render methods.
Basically in order to make this happen you need to create all of these extra elements. Some of them are relatively simple (such as the view data) but some are a bit more complex - for instance the routing data will consider the current WebForms page to be ignored.
The big problem appears to be the HttpContext - MVC pages rely on a HttpContextBase (rather than HttpContext like WebForms do) and while both implement IServiceProvider they're not related. The designers of MVC made a deliberate decision not to change the legacy WebForms to use the new context base, however they did provide a wrapper.
This works and lets you add a partial view to a WebForm:
public class WebFormController : Controller { } public static class WebFormMVCUtil { public static void RenderPartial( string partialName, object model ) { //get a wrapper for the legacy WebForm context var httpCtx = new HttpContextWrapper( System.Web.HttpContext.Current ); //create a mock route that points to the empty controller var rt = new RouteData(); rt.Values.Add( "controller", "WebFormController" ); //create a controller context for the route and http context var ctx = new ControllerContext( new RequestContext( httpCtx, rt ), new WebFormController() ); //find the partial view using the viewengine var view = ViewEngines.Engines.FindPartialView( ctx, partialName ).View; //create a view context and assign the model var vctx = new ViewContext( ctx, view, new ViewDataDictionary { Model = model }, new TempDataDictionary() ); //render the partial view view.Render( vctx, System.Web.HttpContext.Current.Response.Output ); } }
Then in your WebForm you can do this:
<% WebFormMVCUtil.RenderPartial( "ViewName", this.GetModel() ); %>
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我看了一下MVC的源码,看看我能否找出如何做到这一点。 控制器上下文,视图,视图数据,路由数据和html渲染方法之间似乎有很紧密的耦合。 基本上为了实现这一点,您需要创建所有这些额外的元素。 其中一些是相对简单的(如视图数据),但有些更复杂 - 例如,路由数据将考虑当前WebForms页面被忽略。 大问题似乎是HttpContext - MVC页面依赖于HttpContextBase(而不是像WebForms这样的HttpContext),并且同时实现IServiceProvider它们不相关。 MVC的设 ...
-
几天前在https://drupal.org/node/2023489发布的webform 7.x-4.0-alpha8内置了更多的视图支持。您可以选择要在视图中查看的提交数据值。 webform 7.x-4.0-alpha8 released just a few days ago at https://drupal.org/node/2023489 has more Views support built in. You can choose the submission data value that ...
-
阅读本页未正确加载Google地图。 有关技术详细信息,请参阅JavaScript控制台 换句话说,您应该获得一个API密钥才能使用该地图,并在代码中进行设置 Read This page didn't load Google Maps correctly. See the JavaScript console for technical det ...
-
asp.net mvc在剃刀视图中将webform渲染为部分(asp.net mvc render a webform as a partial in a razor view)[2023-08-26]
哦Duh,阅读错误信息...... 我改变了webform的第一行: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.ViewUserControl" %> 对此: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="menu.aspx.cs" Inherits="System.Web.Mvc.Vi ... -
我最终使用javascript通过他们的ID找到角度下拉列表,获取他们的值并在帖子上更新一些隐藏的输入。 它可能不优雅但有效。 I eventually used javascript to find the angular dropdowns by their IDs, get their values and update some hidden inputs on post. It may not be elegant but worked.
-
视图内的局部视图?(Partial view inside a View?)[2021-08-25]
来自部分视图助手的文档 : Partial view helper用于在其自己的变量范围内呈现指定的模板。 主要用途是可重用的模板片段,您无需担心变量名称冲突。 此外,它们允许您指定特定模块的部分视图脚本。 然后,您将使用以下命令从视图脚本中调用它: partial('partial.phtml', array( 'from' => 'Team Framework', 'subject' => 'view partials')); ?> 如果您不需要单独 ... -
如果您只需要在其下方添加文本,那么您可以做的一件事就是将描述添加到表单的最后一个字段,尽管它可能不是您想要的大小。 或者您可以覆盖主题: 在D6中,在主题中使用theme_webform_element()主题功能来覆盖主题的template.php 在D7中,在主题中使用theme_webform_element_wrapper()主题功能来覆盖主题的template.php 使用主题开发人员模块http://drupal.org/project/devel_themer ,它像Firebug一样工作,以 ...
-
MVC - 如何在_Layout中包含部分视图的模型(MVC - How to include a model inside _Layout for Partial View)[2023-06-30]
答案是通过调用@Html.Action() 。 听起来你走在正确的轨道上。 关键是尝试不要传递多个模型,使模型复杂化,或者不必要地使用ViewBag。 相反,只要您想在每个页面上获取信息,请从_Layout调用操作。 例如,您可能有一个名为PartialsController或SharedController的控制器。 public class PartialsController : Controller { [ChildActionOnly] public ActionResult Us ...