MarionetteJS:应用与区域布局 [英] MarionetteJS: Application Regions vs. Layouts

查看:273
本文介绍了MarionetteJS:应用与区域布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读的最新版本(2.3.0)的文件,它是说,现在申请的地区是德precated。


  

应用地区


  
  

警告:pcated此功能去$ P $是pcated德$ P $。代替使用的
  为您的视图树的根应用程序,你应该使用一个布局
  视图。为了您的范围布局视图整个文档,你可以设置
  其报以身体。这看起来可能像下面这样:VAR
  RootView = Marionette.LayoutView.extend({EL:'身体'});


在大多数教程,包括大卫Sulc的书骨干木偶的:一个温柔介绍它使用以下code段为区域添加到应用程序

相反下面的下面的例子,它使用addRegions的,是我应该做的事情呢?

  VAR的ContactManager =新Marionette.Application({});
ContactManager.addRegions({
    mainRegion:#主区域
});VAR ContactView = Marionette.ItemView.extend({
    模板:#whatever
    用户界面:{
        键:.button。
    },
    事件:{
        点击@ ui.button:点击
    },
    点击:函数(){
        的console.log(做的东西在这里...);
    }
});ContactManager.on(开始,函数(){
    VAR contactView =新ContactView({
        型号:someModel
    });
    ContactManager.mainRegion.show(contactView);
});


解决方案

使用一个layoutview代替。

例如,你可以这样做:

  VAR的ContactManager =新Marionette.Application({});
VAR LayoutView = Backbone.Marionette.LayoutView.extend({
  模板:#布局视图模板,  地区:{
    菜单:#menu
    内容:#内容
  }
});ContactManager.layout_view =新LayoutView();
ContactManager.layout_view.render();

我从来没有真正直接添加地区我的应用程序对象。

I was reading the documentation of the latest version (2.3.0) and it is saying that Application Regions are now deprecated.

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' });

In most of the tutorials, including David Sulc's book Backbone Marionette: A Gentle Introduction it uses the following code snippet to add regions to an application.

Instead of the following example below, which uses addRegions, what should I be doing instead?

i.e.

var ContactManager = new Marionette.Application({});
ContactManager.addRegions({
    mainRegion: "#main-region"
});

var ContactView = Marionette.ItemView.extend({
    template: "#whatever",
    ui: {
        button: ".button".
    },
    events: {
        "click @ui.button": "click",
    },
    click: function () {
        console.log("do stuff here...");
    }
});

ContactManager.on("start", function () {
    var contactView = new ContactView({
        model: someModel
    });
    ContactManager.mainRegion.show(contactView);
});

解决方案

Use a layoutview instead.

You could do for example:

var ContactManager = new Marionette.Application({});
var LayoutView = Backbone.Marionette.LayoutView.extend({
  template: "#layout-view-template",

  regions: {
    menu: "#menu",
    content: "#content"
  }
});

ContactManager.layout_view = new LayoutView(); 
ContactManager.layout_view.render(); 

I never actually add regions to my app object directly.

这篇关于MarionetteJS:应用与区域布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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