不推荐使用 Marionette 应用程序区域后的用途 [英] What to use since Marionette Application Regions are deprecated

查看:18
本文介绍了不推荐使用 Marionette 应用程序区域后的用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下链接中的 Marionette (2.3.0) 文档感到困惑,该文档说应用程序区域功能已弃用.应改用布局视图.这是否意味着我不应该再使用 MyApp.addRegions() ?那么我应该如何将我的布局视图添加到我的应用程序中?

I am confused by the Marionette (2.3.0) documentation from the link below that says the Application Regions feature is deprecated. A Layout View should be used instead. Does that mean I should not use MyApp.addRegions() any more? Then how should I add my Layout View to my application?

http://marionettejs.com/docs/marionette.application.html#应用区域

应用领域

警告:已弃用 此功能已弃用.而不是使用应用程序作为您的视图树的根,您应该使用布局看法.要将您的布局视图范围限定到整个文档,您可以设置它的 el 到身体".这可能类似于以下内容:

Warning: deprecated This feature is deprecated. Instead of using the Application as the root of your view tree, you should use a Layout View. To scope your Layout View to the entire document, you could set its el to 'body'. This might look something like the following:

var RootView = Marionette.LayoutView.extend({ el: 'body' });

var RootView = Marionette.LayoutView.extend({ el: 'body' });

推荐答案

我想用一个非常简单的例子来解释一下在marionette中layout view的用法.

I will like to explain with a very simple example the usage of layout view in marionette.

html

   <div id="appDiv"></div>

   <script type="text/template" id="mainTemplate">
       <div id="div1"></div>
       <div id="div2"></div>    
   </script>

    <script type="text/template" id="itemTempFirst">
       <p>some text item 1 view</p>
       <p>some text item view 1</p>
    </script>

     <script type="text/template" id="itemTempSecond">
       <p>some text item 2 view</p>
       <p>some text item view 2</p>
     </script>

JS代码:--

     var app = new Marionette.Application();
     var LayoutViewObj = Marionette.LayoutView.extend({
         template:"#mainTemplate",
         el:"#appDiv",
         regions:{
            reg1:"#div1",
            reg2:"#div2"
         }
     });

      var layoutViewInstance = new LayoutViewObj();
      layoutViewInstance.render();

      var ItemView1Obj = Marionette.ItemView.extend({
         template:"#itemTempFirst"
      });

      var ItemView2Obj = Marionette.ItemView.extend({
         template:"#itemTempSecond"
      });

      var item1 = new ItemView1Obj();

      var item2 = new ItemView2Obj();

      layoutViewInstance.getRegion("reg1").show(item1);

      layoutViewInstance.getRegion("reg2").show(item2);

请注意,我之前尝试不使用 el 元素,但我没有运气,因为我使用了 el:"#someElem" 生活变得更轻松了

Please note I was trying without el element earlier , but i got no luck and as I used el:"#someElem" life got easier

这篇关于不推荐使用 Marionette 应用程序区域后的用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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