【问题标题】:How to show ICollection count in jQuery tmpl?如何在 jQuery tmpl 中显示 ICollection 计数?
【发布时间】:2023-03-09 13:49:01
【问题描述】:

在我的 POCO 模型中,我有一个集合属性定义为

    public virtual ICollection<Position> Positions { get; set; }

现在,在我的 jquery tmpl 中,我想在 jquery tmpl 中显示 Positions 属性的计数,例如

        <span class="Position">${Positions.Count}</span>

但是,它在那里没有显示任何内容(空)。我也没有收到任何错误。有没有办法让它工作?

【问题讨论】:

    标签: jquery icollection


    【解决方案1】:

    添加方法如:

    public virtual ICollection<Position> Positions { get; set; }
    public int Total { get { this.Positions.Count(); }
    

    在您的代码中

    <span class="Position">${Total}</span>
    

    【讨论】:

    • 非常感谢您的快速回复。有用。但是,我很惊讶这不能直接在模板中完成。
    • 这很简单:模板源是一个JSON元素,JSON元素不直接调用.NET代码,因为模板Position是一个对象,不是集合,如果你愿意,你可以调用为您提供数组长度的 javascript 成员是 length${Positions.length} 但是如果Positions 是空的,我不知道它会如何处理,你需要检查它自己的JSON。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 2011-08-02
    • 2011-05-19
    • 2011-04-14
    • 1970-01-01
    • 2011-05-22
    相关资源
    最近更新 更多