简体   繁体   English

灰烬嵌套的应用程序和小部件

[英]Ember nested applications and widgets

I'm designing the intranet web application for our company. 我正在为我们的公司设计Intranet Web应用程序。 One of the app. 应用之一。 requirements is to provide "widget" platform. 要求是提供“小部件”平台。 Which means that developers may create mini application, that will work inside the main web application and can use it's resources. 这意味着开发人员可以创建迷你应用程序,该应用程序可以在主Web应用程序内部运行并可以使用其资源。 Widgets could be independent of applications and they can have there own data models and behaviors. 小部件可以独立于应用程序,并且可以具有自己的数据模型和行为。 My task is to provide widget abstraction and widgets engine within application (widgets management and organizing on the application pages). 我的任务是在应用程序中提供小部件抽象和小部件引擎(小部件管理和在应用程序页面上进行组织)。 I reviewed several JS "MV*" frameworks and it looks like Ember.js is the thing that I want to use. 我回顾了几个JS“ MV *”框架,看起来Ember.js是我要使用的东西。 But I can't understand how to separate in Ember, the abstract functionality between widgets and the application. 但是我不明白如何在Ember中分离小部件和应用程序之间的抽象功能。 From one side, the main application is Ember application by itself that manages current widgets appearance, from other, widgets, are applications to. 从一方面来看,主要应用程序是Ember应用程序,它本身管理着当前小部件的外观,而其他应用程序则是该部件。 Is it possible to have nested apps in Ember, so can make something like: 是否可以在Ember中嵌套应用程序,所以可以进行如下操作:

Widgets.SpecificWidget1 = Em.Application.extend({
   name:"I'm custom widget",
   ready:function(){alert('Widget app Ready')}
});

App = Em.Application.create({
   rootElement:"#widgetsPanel",
   ready:function(){alert('main app Ready')}
});

App.WidgetsController = Em.ArrayController.create({
   widgets:[Widgets.SpecificWidget1.create(),
            Widgets.SpecificWidget1.create(),
            Widgets.SpecificWidget1.create()]
});

App.WidgetsView = Em.View.extend({

});

<div id="widgetsPanel"></div>

<script type="text/x-handelbars">
<ul>
{{#each App.WidgetsController}}
  {{#view App.WidgetsView contentBinding="this"}}
    <li>{{content.name}}</li>
  {{/view}}
{{/each}}
</ul>
</script>

If this way is not correct to do this, can you please tell what is the better way to do it?Thx 如果这样做的方法不正确,可以请您告诉我哪种方法更好吗?

It's hard to tell what's happening in the code, but this is my best guess of what you're trying to do. 很难说出代码中正在发生什么,但这是我对您要尝试执行的操作的最佳猜测。 This isn't designed to work as is, but it should put you on the path to what you want to do: 这并不是按原样设计的,但是它应该使您走上想要做的事情:

Widgets.SpecificWidget1 = Em.Object.extend({
   name:"I'm custom widget",
   ready:function(){alert('Widget app Ready')}
});

Assuming this is supposed to be the base model you're working from, the Widget is extending Ember.Object, as that's a tangible thing. 假设这是您正在使用的基本模型,则该Widget扩展了Ember.Object,因为这是有形的。 As far as I can tell, there's not much to be gained from extending Ember.Application in most use cases, and in a basic scenario where your Ember Application is an entire page, you'll never want more than one. 据我所知,在大多数用例中,扩展Ember.Application并不会带来太多好处,在Ember Application是整个页面的基本情况下,您永远都不会想要超过一个。

App = Em.Application.create({
   rootElement:"#widgetsPanel",
   ready:function(){alert('main app Ready')}
});

App.WidgetsController = Em.ArrayController.create({
   widgets : [Widgets.SpecificWidget1.create(),
              Widgets.SpecificWidget1.create(),
              Widgets.SpecificWidget1.create()]
});

As far as I can tell this is okay. 据我所知这还可以。

App.WidgetsView = Em.View.extend({

});

You don't really gain anything from this by itself. 您本身并不能从中真正获得任何收益。 If you give it a 'templateName' attribute, you can bind it to a particular template defined in Handlebars to get some functionality, and wrap the general Widget to get a better MVC setup going. 如果为它提供了'templateName'属性,则可以将其绑定到在Handlebars中定义的特定模板以获取某些功能,并包装常规Widget以获得更好的MVC设置。 But for what you have, you could remove this. 但是对于您所拥有的,您可以删除它。

For what I'm working on at the moment, I have a design setup that looks like this Fiddle: http://jsfiddle.net/PastryExplosion/99CMD/ 对于目前的工作,我有一个类似于Fiddle的设计设置: http : //jsfiddle.net/PastryExplosion/99CMD/

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

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