Ember.js将params对象传递给linkTo或action helper(Ember.js pass params object to linkTo or action helper)
有没有办法将params对象传递给linTo或action helper?
我有一个对象,它需要复合键。 我正在使用Ember Model并且必须修改适配器。 在获取初始对象的路由器中,我使用必要的密钥传递一个params对象。 当使用linkTo或者使用transitionToRoute时,我的问题是尝试做同样的事情。 据我所知,两者都没有再次击中路由器。
我回到这个问题。 我仍然不确定处理这个问题的正确方法。
App.Router.map(function () { this.resource("clients", { path: 'clients' }, function () { this.resource("client", { path: ':client_id' }, function () { this.resource("claims", function () { this.resource('claim', { path: ':claim_id/:claim_sub' }, function () { this.resource('lines', { path: 'lines' }, function () { this.resource('line', { path: ':line_id' }, function () { this.resource('flags', function () { this.resource('flag', { path: ':flag_id' }); }); }); this.route('claim_lines'); }); }); }); }); }); this.route("errors", { path: '/errors/:error_id' }); });
当我链接到索赔下的任何内容时,复合slu are,我将那些设置为未定义。
UPDATE
序列化正是我所需要的。
App.ClaimRoute = Nucleus.Route.extend({ model: function (params) { params.client_id = this.modelFor('client').get('client_id'); return App.Claim.find('claim', params); }, serialize: function (model) { return { claim_id: model.get('cla_seq'), claim_sub: model.get('cla_sub') }; } });
Is there a way to pass a params object to a linTo or action helper?
I have an object and it needs compound keys. I am using Ember Model and had to modify the adapter. In the Router that gets the initial object i pass a params object with the necessary keys. My problem is trying to do the same thing when using either a linkTo or action with a transitionToRoute. Neither hit the router again as far as I can tell.
Im coming back to this questions. Im still not sure the proper way to handle this.
App.Router.map(function () { this.resource("clients", { path: 'clients' }, function () { this.resource("client", { path: ':client_id' }, function () { this.resource("claims", function () { this.resource('claim', { path: ':claim_id/:claim_sub' }, function () { this.resource('lines', { path: 'lines' }, function () { this.resource('line', { path: ':line_id' }, function () { this.resource('flags', function () { this.resource('flag', { path: ':flag_id' }); }); }); this.route('claim_lines'); }); }); }); }); }); this.route("errors", { path: '/errors/:error_id' }); });
When i link to anything under the claim, where the compound slugs are, i get those set to undefined.
UPDATE
The serialize was just what i needed.
App.ClaimRoute = Nucleus.Route.extend({ model: function (params) { params.client_id = this.modelFor('client').get('client_id'); return App.Claim.find('claim', params); }, serialize: function (model) { return { claim_id: model.get('cla_seq'), claim_sub: model.get('cla_sub') }; } });
原文:https://stackoverflow.com/questions/16723397
最满意答案
您需要处理不同类型的
TypeSyntax
es。 请参见: http : //source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/Syntax/TypeSyntax.cs,29171ac4ad60a546,references您在调试器中看到的是
SimpleNameSyntax
,它具有公共Identifier
属性。更新
var ns = objectCreationExpressionSyntax.Type as NameSyntax; if (ns != null) { return ns.Identifier.ToString(); } var pts = objectCreationExpressionSyntax.Type as PredefinedTypeSyntax; if (pts != null) { return pts.Keyword.ToString(); } ...
所有其他子类型都需要交付。 请注意,
ArrayType.ElementType
也是一个TypeSyntax
,因此您很可能需要使此方法递归。You'll need to handle the different types of
TypeSyntax
es. See here: http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/Syntax/TypeSyntax.cs,29171ac4ad60a546,referencesWhat you see in the debugger is a
SimpleNameSyntax
, which does have a publicIdentifier
property.Update
var ns = objectCreationExpressionSyntax.Type as NameSyntax; if (ns != null) { return ns.Identifier.ToString(); } var pts = objectCreationExpressionSyntax.Type as PredefinedTypeSyntax; if (pts != null) { return pts.Keyword.ToString(); } ...
All other subtypes would need to be handed. Note that
ArrayType.ElementType
is also aTypeSyntax
, so you would most probably need to make this method recursive.
相关问答
更多-
所以,事实证明, CSharpCompilationOptions.Usings在编译脚本文件时只在编译器中检查过。 如果你追踪引用,它最终会在if (inScript)检查中在这里使用。 我们可能需要更好地记录。 So, it turns out that CSharpCompilationOptions.Usings is only ever examined in the compiler when compiling script files. If you trace through the re ...
-
为您正在访问/重写的节点询问SymbolInfo的SemanticModel 。 它返回的符号应始终是一个带有属性的IMethodSymbol ,它包含构造函数的所有参数。 出于好奇,我写了一个SyntaxRewriter ,它完全符合你的需求。 它当然没有经过彻底的测试,会有一些我错过的(或者只是省略了,就像已经命名的参数一样)。 public class NameAllParametersRewriter : CSharpSyntaxRewriter { private readonly Sem ...
-
IdentifierName()就是 - 标识符的名称。 你问了一个名为double的标识符,它为你提供了一个有效的语法。 您需要SpecialType重载 : generator.TypeExpression(SpecialType.System_Double) An IdentifierName() is exactly that – the name of an identifier. You asked for an identifier named double, and it gave you ...
-
一个选项是使用注释标记所有方法,添加using语句,使用注释查找方法,更改所有方法以及删除注释。 正如你所说,树是不可变的,但修改过程中注释不会丢失。 所以你需要以下内容: var annotation = new SyntaxAnnotation(); var newRoot = root.ReplaceNode( method, method.WithAdditionalAnnotations(annotation)); newRoot = AddUsing(newRoot); me ...
-
IdentifierStart和IdentifierPart都只匹配一个字符。 因此,如果规则是IdentifierName -> IdentifierStart IdentifierPart ,它只会匹配长度恰好为2的标识符,而您的第二个建议将匹配长度为1或2的标识符。 递归是规则如何匹配任意长度的标识符。 以下是你如何推导出“git”: IdentifierName / \ IdentifierN ...
-
可悲的是,我认为没有一个良好的公共方式来做到这一点。 请参阅Roslyn的内部DetermineParameter助手,以获取可能有用的内容。 Sadly I don't think there is a good public way to do this. See Roslyn's internal DetermineParameter helper for something that might help.
-
您可以安装Roslyn 语法Visualizer ,它将向您显示语法树,也可以让您探索SemanticModel API。 安装完成后,您可以尝试右键单击节点并询问类型符号: 在这种情况下,你会发现一些事情: 如果使用“View TypeSymbol(如果有)”,您可以从ObjectCreationExpression本身获取符号,但不能从其任何子node获取符号(“IdentifierName”或“ArgumentList”),因此可以通过将node传递给GetTypeInfo而不是node.Type 。 ...
-
那么你几乎就在那里,你只需要创造所有这些。 这应该做你感兴趣的事情: const string source = @" using System; class MyClass { void Method() { MyClass nameOfVariable; } } "; var tree = CSharpSyntaxTree.ParseText(source); var compilation = CSharpCompilation.Create("MyCompi ...
-
您需要处理不同类型的TypeSyntax es。 请参见: http : //source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/Syntax/TypeSyntax.cs,29171ac4ad60a546,references 您在调试器中看到的是SimpleNameSyntax ,它具有公共Identifier属性。 更新 var ns = objectCreationExpressionSyntax.Type as NameSyntax; if (ns != ...
-
问题是, VisitAssignmentExpression中的代码在遇到赋值表达式时会立即停止语法遍历。 如果要继续遍历其子节点,可以添加base.VisitAssignmentExpression(node); 方法。 The issue is that your code in VisitAssignmentExpression stops the syntax walk as soon as it encounters an assignment expression. If you want to ...