如何从Ember.Object创建计算别名到控制器的属性?

时间:2014-12-23 15:25:05

标签: ember.js appkit ember-app-kit

我的全局问题是在控制器中创建一个ACL对象,它提供所有操作的列表,只是其中一部分可供使用。可访问的操作取决于控制器属性。我喜欢从actions到控制器的每个属性创建一个计算属性。如何从控制器的嵌套对象属性到控制器属性创建计算属性?我确实创建了片段来说明我的问题。



var App = window.App = Ember.Application.create();

var AccessibleMixin = Em.Mixin.create({
  list: [
    Ember.Object.createWithMixins({
      name: "Permitted to write",
      isAccessible: Ember.computed.alias('isWritable')
    }),
    Ember.Object.createWithMixins({
      name: "Permitted to read",
      isAccessible: Ember.computed.alias('isReadable')
    })
  ]
});


App.IndexController = Ember.ObjectController.extend(AccessibleMixin, {
  model: {
    isWritable: true,
    isReadable: false
  },
  init: function() {
    var first = this.get('list.firstObject');
    console.log(first);
  },
});

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <link rel="stylesheet" href="//wheely.github.io/ember-dialog/css/ember.dialog.min.css">
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="//builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script>
  <script src="//builds.emberjs.com/tags/v1.8.1/ember.prod.js"></script>
</head>

<body>
  <script type="text/x-handlebars" data-template-name="index">
    {{#each list}}
    <div>{{name}}: {{#if isAccessible}}YES{{else}}NO{{/if}}</div>
    {{/each}}
  </script>
</body>

</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案