1

** 我使用 Ember.Object 而不是 Ember Data,从 api 中提取数据,我相信这可能会导致问题。**

我的资源嵌套如下:

Mdm.Router.map ->
 @resource "groups", ->
   @resource "group", path: ':group_id'

'/groups/ 在浏览器左侧加载所有组的列表。每个组都链接到其特定的 group_id。单击时,“组”模板会在屏幕右侧呈现,显示一个组的详细信息,而列表保留在左侧。

但是,当您单击后退按钮或手动将 group_id 输入 url 时,各个组不会呈现。url 将在浏览器窗口中更新,但内容不会更改以匹配它。

我在带有 {{outlet}} 的“组”模板中呈现了单一的“组”模板。

我的 groups_route.js.coffee 看起来像这样:

Mdm.GroupsRoute = Ember.Route.extend(model: ->
   Mdm.Group.all()
)

应用程序.hbs:

<div class="container">
  <div class="nav-bar">
    <img src="assets/logo_loginbox.png" class="logo">
    <ul class="nav-menu">
      <li>GROUPS</li>
      <li>USERS</li>
    </ul>
  </div><!-- nav-bar -->
  <hr>
  {{outlet}}
</div><!-- container -->

组.hbs:

<h1>Groups</h1>

{{ partial groupsList }}
<div class="group">
  {{outlet}}
</div><!-- group -->

组.hbs:

<h1>{{name}}</h1>

当我使用后退按钮或尝试加载存在 group_id 的页面时,我在控制台中收到以下错误:

Uncaught TypeError: Object function () {
if (!wasApplied) {
  Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
var m = meta(this);
m.proto = this;
if (initMixins) {
  // capture locally so we can clear the closed over variable
  var mixins = initMixins;
  initMixins = null;
  this.reopen.apply(this, mixins);
}
if (initProperties) {
  // capture locally so we can clear the closed over variable
  var props = initProperties;
  initProperties = null;

  var concatenatedProperties = this.concatenatedProperties;

  for (var i = 0, l = props.length; i < l; i++) {
    var properties = props[i];

    Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin));

    for (var keyName in properties) {
      if (!properties.hasOwnProperty(keyName)) { continue; }

      var value = properties[keyName],
          IS_BINDING = Ember.IS_BINDING;

      if (IS_BINDING.test(keyName)) {
        var bindings = m.bindings;
        if (!bindings) {
          bindings = m.bindings = {};
        } else if (!m.hasOwnProperty('bindings')) {
          bindings = m.bindings = o_create(m.bindings);
        }
        bindings[keyName] = value;
      }

      var desc = m.descs[keyName];

      Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
      Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1));

      if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
        var baseValue = this[keyName];

        if (baseValue) {
          if ('function' === typeof baseValue.concat) {
            value = baseValue.concat(value);
          } else {
            value = Ember.makeArray(baseValue).concat(value);
          }
        } else {
          value = Ember.makeArray(value);
        }
      }

      if (desc) {
        desc.set(this, keyName, value);
      } else {
        if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
          this.setUnknownProperty(keyName, value);
        } else if (MANDATORY_SETTER) {
          Ember.defineProperty(this, keyName, null, value); // setup mandatory setter
        } else {
          this[keyName] = value;
        }
      }
    }
  }
}
finishPartial(this, m);
delete m.proto;
finishChains(this);
this.init.apply(this, arguments);
  } has no method 'find' application.js:51233
Mdm.GroupRoute.Ember.Route.extend.model application.js:51233
superWrapper application.js:12849
Ember.Route.Ember.Object.extend.deserialize application.js:36503
collectObjects application.js:35614
proceed application.js:35638
(anonymous function) application.js:1193
fire application.js:1038
self.fireWith application.js:1149
(anonymous function) application.js:1200
fire application.js:1038
self.fireWith application.js:1149
done application.js:8075
script.onload.script.onreadystatechange
4

0 回答 0