- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很困惑为什么Route
和Controller
会影响默认的Model
。这是一个例子。
App.ApplicationRoute = Ember.Route.extend({
setupController: function(controller, model) {
this._super(controller, model);
console.log(model); //returns undefined
controller.set("title", "Page title");
}
});
上面的代码片段工作没有错误;模板按预期打印 {{title}}
。请注意,该模型是“未定义的”。
App.ApplicationRoute = Ember.Route.extend({
setupController: function(controller, model) {
this._super(controller, model);
console.log(model); //returns undefined
controller.set("title", "Page title");
}
});
App.ApplicationController = Ember.ObjectController.extend({});
上面的代码抛出错误 ...
(Error while processing route: index Assertion Failed: Cannot delegate set('title', Page title) to the 'content' property of object proxy : its 'content' is undefined.)
...并产生一个空白页。解决方案是返回模型(空白对象)或使用Controller
(默认行为)而不是ObjectController
。有人可以解释一下这种特殊情况吗?为什么 Ember 在使用 ObjectController
时不假设一个空对象?是否假设对象将从商店或服务器传入或检索?
App.ApplicationRoute = Ember.Route.extend({
model: function() {
return {};
},
setupController: function(controller, model) {
this._super(controller, model);
console.log(model);
controller.set("title", "Page title");
}
});
App.ApplicationController = Ember.ObjectController.extend({});
最佳答案
如 Ember docs 中所述:
Ember.ObjectController is part of Ember's Controller layer. It is intended to wrap a single object, proxying unhandled attempts to get and set to the underlying model object, and to forward unhandled action attempts to its target.
ObjectController 期望存在一个模型并将其设置为内容。它基本上是单个对象的包装。
关于javascript - Ember.js Route.setupController 和 ObjectController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26495311/
因此,我的 route 有两条路径。我将这两条路线创建为 doc recommends . 我的路由器如下: // router.js Router.map(function() { this.r
Emberjs v1.0.0-pre.4 Handlebars 1.0.0.rc.2 我正在 ember 中构建一个 Facebook 好友列表管理器。当我导航到 list/1/members 时,M
我正在设置isActive在 setupController 中: App.EntryRoute = Ember.Route.extend setupController: (controll
假设我有一个观点: CellarRails.SearchTextField = Ember.TextField.extend({ templatename: 'index', insertNe
我有以下路线和 Controller : var App = App || Ember.Application.create(); App.Router.map(function(){ this.
Ember-Data 很棒,但我需要一些自定义的东西来通过 invitation_token 获取用户,而且还完全在后端 Rails 端调用不同的 Controller 操作。 这是我的路线: MyE
我试图在输入登录路由后立即设置 Controller 属性。目前,我正在使用方法1,它依赖于 Controller 中的init。它工作正常,但我的理解是最好在路由中使用 setupControlle
我在 Ember.js 官方教程中看到了很多令人困惑的例子。 我真的不喜欢的一个例子是: App.ApplicationRoute = Ember.Route.extend({ setupCo
我很困惑为什么Route和Controller会影响默认的Model。这是一个例子。 App.ApplicationRoute = Ember.Route.extend({ setupCont
我有一个 Controller ,上面附加了一些方法。我有相关的路线。我在 Controller 中添加了这些方法,以便它们可以在其他一些地方重复使用。这些方法从服务器检索一些数据。在路线的 setu
我的 route 有一个 setupController 和 model Hook 。 model.find(param) 保存对 Rails 后端的 ajax 调用。 发生的情况是我的模型钩子(Ho
如何在 ember 中将属性从一个 Controller 传递到另一个 Controller 而不涉及路由的 setupController 最佳答案 在最简单的情况下,您可以将一个 Controll
我目前正在评估 Ember.js,因此我正在构建一个小型示例应用程序。目前到目前为止一切都很顺利,但现在我似乎无法解决我最后一个小问题。 当我通过路线电影正常访问应用程序时,一切都按预期进行。显示电影
在使用 {{linkTo}} 时有什么原因导致 setupController 不会被调用吗?我的应用程序中有两个使用 linkTo 的实例,在第二种情况下。它不起作用。我能看到的唯一区别是,在第一种
我有一个没有明确创建 Controller 文件的路由。我的路线看起来像: import Ember from 'ember'; import ApplicationRouteMixin from '
我对 Ember.Route 模型与 setupController 有一些困惑。我在这里有一个示例应用程序: http://jsbin.com/ihakop/5/edit 我想知道为什么我需要添加以
我试图理解 setupController和 model钩子(Hook),它们只会在动态段的情况下被调用吗? 这是我的路由器配置,我看到应用程序运行良好,但我没有看到这些钩子(Hook)被执行: //
我在 formGroup 中遇到问题。首先,我根据 URL 取一些值并调用 API 来检索前字段文本的特定用户数据。 注册.html Username
我有一条路线 /users/:user_id在 emberjs 应用程序中,我将模型分配给 App.UserRoute 类的 setupController Hook 中的模板,如下所示: contr
目前,我正在浏览 Ember.js 指南中的每一页和代码片段,并构建一个小型示例应用程序。有些我已经坚持了一段时间但解决了。然而,这个让我感到困惑。 在 http://emberjs.com/guid
我是一名优秀的程序员,十分优秀!