简体   繁体   English

Enyo MVC实现和粒子视图渲染

[英]Enyo MVC implementation and particle view rendering

Could you please help me with MVC implementation with enyojs framework The current goal is to implement N -panels (displays, windows) for TV application which would be changed after button was pressed (channel switch for instance). 您能帮我用enyojs框架实现MVC吗?当前目标是为电视应用程序实现N个面板(显示器,窗口),按下按钮(例如,频道切换)后即可更改。 It looks just like simple redirect to new URL (or controller's action) in web. 看起来就像简单重定向到Web中的新URL(或控制器的操作)。 So, we want to re-render views and parts of views and update windows(panels) using strategy of keeping just 2 displays at the same time (current and next we go with animation). 因此,我们想重新渲染视图和部分视图,并使用同时仅保留两个显示的策略来更新窗口(面板)(当前和下一个动画)。 I learned some examples of MVC with enyo from other topics here, but that implementations of MVC but some questions are still exist. 我从这里的其他主题中学到了带有enyo的MVC的一些示例,但是MVC的实现仍然存在一些问题。

Problem: how to implement in enyo the particle updating of the view with new data from controller ? 问题:如何用来自控制器的新数据来实现视图的粒子更新?

//--- app.js
enyo.kind({
    name: "my.Application",
    kind: "enyo.Application",
    view: "Index", // default start view    
    controllers: [ // I use 2.3 version and know about this rudiment property.
                {name: "homeController", kind: "HomeController"}                
            ],          
    viewChanged : function() { 
        this.inherited(arguments); 
        app.render();  // this updates the view. Changes from index to edit and back. 
    }   
});

enyo.ready(function () {
    app = new my.Application({name: "app"});
});


//------  controller.js + IndexView.js + editview.JS


enyo.kind({
    name : "IndexView",
    kind: "enyo.View",
    components: [
                 {content: "HelloWorld,  This is Index"},
                 {content: "This is the Index view"},
                 {kind: "moon.ToggleButton", content: "Show Edit", ontap: "buttonTapped"}
                 ],
    // redirect to Edit View
    buttonTapped: function(sender, event){
        app.controllers.homeController.Edit("message(model) to Edit View");
    }

});


enyo.kind({
    name : "EditView",
    kind: "enyo.View",
    message: "no msg",
    components: [
                 {name: "headWithId", content: "Hello! This is EDIT."},
                 {content: "This is the Edit view"},
                 {kind: "moon.ToggleButton", content: "Show Index", ontap: "buttonTapped"}
    ],

    bindings: [
              {from: ".message", to:".$.headWithId.content"}
    ],

    // redirect to Index View
    buttonTapped: function(sender, event){              
        app.controllers.homeController.Index();     
    }
});


enyo.kind({
    name : "HomeController",
    kind: "enyo.Controller",

    Index : function(){     
        app.set("view", new  IndexView()); // this code updates the view of app, but maybe there is a better way to do it?      
    },

    Edit : function(msg){
        app.set("view", new  EditView({message: msg}));     
    }

});

The previous code works find. 前面的代码可以找到。 There some question in comments. 评论中有一些问题。 But how to implement such situation, then I don't want to rerender all the divs of the view, but just particle content (for example, leave the header and update the content): 但是如何实现这种情况,那么我不想重新渲染视图的所有div,而只是重新渲染粒子的内容(例如,保留标题并更新内容):

// ----- baselayoutview.js

enyo.kind({
    name : "BaseLayout",
    kind: "enyo.ViewController", // or enyo.View... what is better?
    components: [
                 {content: "this content of the  View never changes"},
                     // next content should be changed. It's for renderTarget 
                 {name: "RenderContentSection"} // How to render new content form Index or Edit view here?
            ]

});

// ----- app.js

enyo.kind({
    name: "my.Application",
    kind: "enyo.Application",
    view: "BaseLayout",  // We set this base layout view and expect the it will fill it's content by itself 

    controllers: [
                {name: "homeController", kind: "HomeController"}                
            ],

    viewChanged : function() { 
        this.inherited(arguments); 
        app.render("RenderContentSection");  // I think it would not be working any more.. but what it the best way to do it? How to update BaseLayout view's RenderContentSection ?
    }

});

You should not be calling app.render() to re-render your application. 您不应该调用app.render()重新呈现您的应用程序。 As you say, you don't want to re-render the whole thing each time. 正如您所说,您不想每次都重新渲染整个东西。 Are you stuck on Enyo 2.3 or can you update to a more recent version? 您是否仍然使用Enyo 2.3,还是可以更新到最新版本? Controllers have been largely deprecated, for one. 控制器已被大量弃用。

I suggest taking a look at the Panels component. 我建议看一下面板组件。 You can place a Panels component within your area that changes and navigate to a panel and push whatever content you want into that panel. 您可以将面板组件放置在变化的区域内,并导航到面板,然后将所需的任何内容推入该面板。 You individual sections would be Panel components and you can push and pop those as needed. 您的各个部分将是Panel组件,您可以根据需要推送和弹出它们。 If you need to replace the panel. 如果需要更换面板。

If you really want to do it that way, you can modify your BaseLayout component so that it uses createComponent() to create whichever partial view you want. 如果您确实想这样做,则可以修改BaseLayout组件,以便它使用createComponent()创建所需的任何局部视图。

enyo.kind({
    name : "BaseLayout",
    // This can be just a plain enyo.Control
    components: [
         {content: "this content of the  View never changes"},
         // next content should be changed. It's for renderTarget 
         {name: "renderContentSection"} // How to render new content form Index or Edit view here?
    ],
    replacePartial: function(partial) {
        this.$.renderContentSection.destroyClientControls();
        this.$.renderContentSection.createComponent({kind: partial});
        this.$.renderContentSection.render();
    }
});

Here's a fiddle showing that off: http://jsfiddle.net/RoySutton/LhjLv6hy/ 这是一个炫耀的小提琴: http : //jsfiddle.net/RoySutton/LhjLv6hy/

You could create a new control with a 'chrome' controls and a client area that controls get rendered into, but this is pretty simple. 您可以创建一个带有“ chrome”控件和一个呈现控件的工作区的新控件,但这非常简单。 Still, take a look at Panels. 不过,请看一下面板。 It's what they were designed for. 这就是他们的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM