使用什么样的,因为木偶应用区域是德precated [英] What to use since Marionette Application Regions are deprecated
问题描述
我被弄得木偶(2.3.0)从下面的链接文件说,应用区域功能去precated。布置图应改为使用。这是否意味着我不应该使用 MyApp.addRegions()
了吗?那么应该怎么加我的布局视图我的应用?
<一个href=\"http://marionettejs.com/docs/marionette.application.html#application-regions\">http://marionettejs.com/docs/marionette.application.html#application-regions
应用地区
警告:pcated此功能去$ P $是pcated德$ P $。代替使用的
为您的视图树的根应用程序,你应该使用一个布局
视图。为了您的范围布局视图整个文档,你可以设置
其报以身体。这看起来可能像下面这样:
VAR RootView = Marionette.LayoutView.extend({EL:'身体'});
块引用>解决方案我想用一个非常简单的例子木偶布局视图的使用来解释。
HTML
&LT; DIV ID =appDiv&GT;&LT; / DIV&GT; &LT;脚本类型=文/模板ID =mainTemplate&GT;
&LT; DIV ID =DIV1&GT;&LT; / DIV&GT;
&LT; DIV ID =DIV2&GT;&LT; / DIV&GT;
&LT; / SCRIPT&GT; &LT;脚本类型=文/模板ID =itemTempFirst&GT;
&LT; P&GT;一些文本项目1查看&LT; / P&GT;
&LT; P&GT;一些文本项目视图1 LT; / P&GT;
&LT; / SCRIPT&GT; &LT;脚本类型=文/模板ID =itemTempSecond&GT;
&LT; P&GT;一些文本项目2查看&LT; / P&GT;
&LT; P&GT;一些文本项目视图2'; / P&GT;
&LT; / SCRIPT&GT;JS code: -
VAR应用=新Marionette.Application();
VAR LayoutViewObj = Marionette.LayoutView.extend({
模板:#mainTemplate
EL:#appDiv
地区:{
REG1:#DIV1
REG2:#DIV2
}); VAR layoutViewInstance =新LayoutViewObj();
layoutViewInstance.render(); VAR ItemView1Obj = Marionette.ItemView.extend({
模板:#itemTempFirst
}); VAR ItemView2Obj = Marionette.ItemView.extend({
模板:#itemTempSecond
}); VAR ITEM1 =新ItemView1Obj(); VAR ITEM2 =新ItemView2Obj(); 。layoutViewInstance.getRegion(REG1)显示(ITEM1); 。layoutViewInstance.getRegion(REG2)显示(ITEM2);请注意,我试图不EL元件较早,但我没有运气,为我所用EL:#someElem的生活变得更容易。
感谢
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#application-regions
Application Regions
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' });
解决方案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 Code:--
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);
Please note I was trying without el element earlier , but i got no luck and as I used el:"#someElem" life got easier
Thanks
这篇关于使用什么样的,因为木偶应用区域是德precated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!