对于我的AngularJS项目(v1.2.3),我有一个路由列表,我正在尝试从对象构建导航栏.我想要做的是isRight在一种样式中显示具有未定义属性的任何对象,并在另一种样式中定义属性.
在一个ng-repeat我想过滤那些具有未定义isRight属性的对象.如何在ng-repeat属性内完成此操作,而无需求助于创建自定义过滤器功能?
$scope.nav = [
{ path: '/', title: 'Home' },
{ path: '/blog', title: 'Blog' },
{ path: '/about', title: 'About' },
{ path: '/login', title: 'Login', isRight: true }
];
Run Code Online (Sandbox Code Playgroud)
我意识到我可以只isRight: false为每个对象添加属性,或者为左右侧链接添加单独的导航对象,以及其他这样简单的解决方法,但我很好奇是否有办法用当前结构完成此操作,使用的界限:
<li ng-repeat="link in nav | filter:{isRight:undefined}">
Run Code Online (Sandbox Code Playgroud)
这更像是一种好奇而不是需要,但我感谢任何建议.
是否可以使用Razor语法定义lambda表达式(delegate,Action,Func <>)的内容,以便在视图中执行此模型方法时,它将插入Razor内容?
这样做的目的是让我们的开发人员能够定义他们自己的自定义内容,以便插入CustomControl视图中的特定点.
以下是模拟我当前布局的精简示例代码.焦点的特定部分是RenderSideContent方法定义及其执行调用.
Index.cshtml
@model My.PageModel
@My.CustomControl(new CustomControlModel
{
AreaTitle = "Details",
RenderSideContent = () =>
{
<div>
@using (My.CustomWrapper("General"))
{
My.BasicControl(Model.Controls[0])
}
</div>
}
})
Run Code Online (Sandbox Code Playgroud)
CustomControl.cshtml
<div>
@Model.AreaTitle
<div class="my-custom-content">
@Model.RenderSideContent()
</div>
</div>
Run Code Online (Sandbox Code Playgroud)