关于 emberjs 中命名约定的困惑 [英] Confusion about naming conventions in emberjs
问题描述
也许有些人只知道答案,但我试图理解以下内容:
Perhaps some folks just know the answer, but I am trying to understand the following:
假设您要声明一个视图:
Say you are declaring a view:
App.FooView = Ember.View.extend({});
现在在 App.Router
中引用此视图会导致以下错误:
Now referencing this view in App.Router
results in the following error:
router.get('applicationController').connectOutlet('Foo')
当我引用 Foo 时,控制台指出:未捕获的错误:断言失败:您提供的名称 Foo 未解析为控制器 FooController
When I reference Foo the console states: Uncaught Error: assertion failed: The name you supplied Foo did not resolve to a controller FooController
我在解释 args 的文档中找不到任何地方.也许投反对票的人实际上可以为解决方案做出贡献.
I could not find anywhere in the docs explaining the args. Perhaps the person who downvoted could actually contribute to the solution.
推荐答案
当您连接插座时,路由器会查找与提供的控制器名称相同的控制器和视图.在您列出的示例中,路由器正在寻找 FooController 和 FooView,但没有找到控制器.如果你想指定更多细节,你可以传递一个包含视图、控制器和上下文的选项对象,如下所示:
When you connect an outlet, the router looks for both a controller and a view the having the same name as the one supplied. In the example you listed, the router is looking for a FooController and a FooView, and is not finding the controller. If you would like to specify more details you can pass an options object with the view, controller and context, like so:
router.get('applicationController').connectOutlet( {
outletName: 'master',
controller: 'fooController',
view: 'fooView',
context: data
});
来自文档:
connectOutlet: function(name, context) {
// Normalize arguments. Supported arguments:
//
// name
// name, context
// outletName, name
// outletName, name, context
// options
//
// The options hash has the following keys:
//
// name: the name of the controller and view
// to use. If this is passed, the name
// determines the view and controller.
// outletName: the name of the outlet to
// fill in. default: 'view'
// viewClass: the class of the view to instantiate
// controller: the controller instance to pass
// to the view
// context: an object that should become the
// controller's `content` and thus the
// template's context.
语法和代码格式
这篇关于关于 emberjs 中命名约定的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!