如何在Ember中创建对话框等控件?

sec*_*tlm 5 jquery-ui ember.js

我想创建一个像对话框一样的控件,以便在需要时重用Ember.Dialog将使用Jquery库的$('foo').对话框函数来实现它.例如:

Ember中的对话框控件

你能给我任何想法和例子吗?谢谢.

pan*_*atz 9

Luke Melia创建了一个存储库,显示了如何在jQuery UI中使用Ember.js.

基于Luke的例子,我创建了一个JQ.Dialog代表jQuery UI对话框的类,请参阅http://jsfiddle.net/pangratz666/aX7x8/:

// Create a new mixin for jQuery UI widgets using the Ember
// mixin syntax.
JQ.Widget = Em.Mixin.create({
    // as defined in
    // https://github.com/lukemelia/jquery-ui-ember/blob/master/js/app.js#L9-95
    ...
});

JQ.Dialog = Ember.View.extend(JQ.Widget, {
    uiType: 'dialog',
    uiOptions: 'autoOpen height width'.w(),

    autoOpen: false,

    open: function() {
        this.get('ui').dialog('open');
    },
    close: function() {
        this.get('ui').dialog('close');
    }
});
Run Code Online (Sandbox Code Playgroud)

然后创建对话框,如下所示:

var dialog = JQ.Dialog.create({
    height: 100,
    width: 200,
    templateName: 'dialog-content'
});
dialog.append();

Ember.run.later(function(){
    dialog.open();
}, 1000);
Run Code Online (Sandbox Code Playgroud)


除了jQuery UI,你可以使用flame.js,一个Ember.js的widget/UI库.该项目支持Panel,请参阅http://jsfiddle.net/qUBQg/:

// the following code sample has been taken from http://jsfiddle.net/qUBQg/
App.TestPanel = Flame.Panel.extend({
    layout: { width: 400, height: 200, centerX: 0, centerY: -50 },
    // Controls whether all other controls are obscured (i.e. blocked
    // from any input while the panel is shown)
    isModal: true,
    // This controls the visual effect only, and works only if
    // isModal is set to true
    dimBackground: true,
    // Set to false if you want to e.g. allow closing the panel only
    // by clicking some button on the panel (has no effect if isModal
    // is false)
    allowClosingByClickingOutside: true,
    // Allow moving by dragging on the title bar - default is false
    allowMoving: true,
    // Title is optional - if not defined, no title bar is shown
    title: 'Test Panel',

    // A Panel must have exactly one child view named contentView
    contentView: Flame.LabelView.extend({
        layout: { left: 20, top: 90, right: 20, bottom: 20 },
        textAlign: Flame.ALIGN_CENTER,
        value: 'This is a panel.'
    })
});

// later in the code
App.TestPanel.create().popup();
Run Code Online (Sandbox Code Playgroud)