0

我的全局问题是在控制器中创建一个 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>

4

0 回答 0