首页 \ 问答 \ AngularJS orderBy日期过滤器无法使用Firebase(AngularJS orderBy date filter not working using Firebase)

AngularJS orderBy日期过滤器无法使用Firebase(AngularJS orderBy date filter not working using Firebase)

我正在使用Firebase来存储我的数据,我知道Firebase将数据存储为对象而不是数组。 我已经解决了这个问题,并且有其他过滤器正常工作,但是当我尝试在我的ng-repeat中使用“orderBy:'date'”时,它不起作用。 这是标记:

<div ng-repeat="event in events | limitTo:10 | filter:tfilter | orderBy: 'date'>
  <div class="row">
    <div class="col-md-6">
       <h4>{{event.date | amDateFormat:'MMMM Do'}}</h4>
    </div>
    <div class="col-md-6">
       <h4>{{event.name}}</h4>
    </div>
  </div>
 </div>

我也尝试过使用orderBy:'event.date',但这也没用。 有人知道解决方案吗?


I'm using Firebase to store my data and I am aware that Firebase stores data as objects and not arrays. I have fixed that problem and have other filters working, but when I try to use "orderBy: 'date'" in my ng-repeat, it does not work. Here is the markup:

<div ng-repeat="event in events | limitTo:10 | filter:tfilter | orderBy: 'date'>
  <div class="row">
    <div class="col-md-6">
       <h4>{{event.date | amDateFormat:'MMMM Do'}}</h4>
    </div>
    <div class="col-md-6">
       <h4>{{event.name}}</h4>
    </div>
  </div>
 </div>

I've also tried using orderBy: 'event.date', but this did not work either. Anyone know the solution?


原文:https://stackoverflow.com/questions/26152142
更新时间:2022-09-21 16:09

最满意答案

枚举的一点是您创建一个只能采用固定值新类型 。 因为在实际使用中只有很多间隔,并且因为在这里创建新类型比使用整型常量更方便,所以对于您的间隔使用枚举是合适的。

你的和弦的故事是不同的。 你已经有了和弦的类型,所以把它们包装在另一个枚举类型中是没有用的。 另外,和弦的数量远没有限制。 我手边的和弦图表显示了22种形状,但不包括反转。 你的和弦结构远比用enum限制和弦更合适。

除了枚举之外,C还有另外两种创建“常量”的机制:预处理器定义和静态变量。

使用预处理器指令,我们可以定义一个Chord文字。 IIRC结构文字是C99的东西,以前只能有初始化文字。

#define CHORD_MAJOR ((Chord){"maj", {ROOT, MAJOR_THIRD, PERFECT_FIFTH}})

有了一个静态变量,你可以在头文件中声明一个对象:

static const Chord chord_major = {"maj", {ROOT, MAJOR_THIRD, PERFECT_FIFTH}};

请注意,C没有像::这样的名称空间运算符。 相反,你必须自己为任何可能的冲突标识符加上前缀。 C ++确实有名称空间,但这不会影响在此答案中所做的要点。


The point of an enum is that you create a new type that can only take on a fixed set of values. It is appropriate to use an enum for your intervals because there are only so many intervals in actual use, and because creating a new type is more convenient than using integer constants here.

The story is different for your chords. You already have a type for your chords, so wrapping them in another enum type is not helpful. Also, the number of chords is far less finite. A chord chart I have at hand shows 22 shapes, but that does not include inversions. Your chord struct is far more appropriate than artificially limiting chords with an enum.

C has two other mechanisms to create “constants” other than enums: preprocessor-defines and static variables.

With a preprocessor directive, we can define a Chord literal. IIRC struct literals are a C99 thing, previously there could only be initializer literals.

#define CHORD_MAJOR ((Chord){"maj", {ROOT, MAJOR_THIRD, PERFECT_FIFTH}})

With a static variable, you would declare an object in a header:

static const Chord chord_major = {"maj", {ROOT, MAJOR_THIRD, PERFECT_FIFTH}};

Note that C does not have a namespace operator like ::. Instead, you have to prefix any possibly clashing identifiers yourself. C++ does have namespaces, but that doesn't affect the points made in this answer.

相关问答

更多
  • 我可以定义一个类型作为枚举的基础类型吗? 您只能使用整数类型来定义enum ,而不是任何旧类型。 例如,你可以使用 enum E : char { A, B, C }; 表明E的值将是char类型。 但是你不能使用 enum E : S { A, B, C }; 从C ++ 11标准3.9.1 / 7 : 类型bool , char , char16_t , char32_t , wchar_t以及有符号和无符号整数类型统称为整型。 整数类型的同义词是整数类型。 Can I define ...
  • 枚举的一点是您创建一个只能采用固定值的新类型 。 因为在实际使用中只有很多间隔,并且因为在这里创建新类型比使用整型常量更方便,所以对于您的间隔使用枚举是合适的。 你的和弦的故事是不同的。 你已经有了和弦的类型,所以把它们包装在另一个枚举类型中是没有用的。 另外,和弦的数量远没有限制。 我手边的和弦图表显示了22种形状,但不包括反转。 你的和弦结构远比用enum限制和弦更合适。 除了枚举之外,C还有另外两种创建“常量”的机制:预处理器定义和静态变量。 使用预处理器指令,我们可以定义一个Chord文字。 IIR ...
  • 枚举类型是ReadJson的objectType参数。 但是,有几点: 您需要处理可为空的枚举类型。 你需要处理[Flag]列举。 Json.NET将它们写成逗号分隔的值列表。 您需要处理具有无效值的枚举的情况。 Json.NET在StringEnumConverter.AllowIntegerValues == true时将它们作为数值写入,否则会引发异常。 这里是StringEnumConverter的子类,通过调用基类来处理这些情况,然后在适当的时候添加或删除类型前缀: public class Ty ...
  • 要在UI5中创建枚举类型, 需要考虑以下某些规则: 枚举定义必须是普通对象 。 在内部,它通过jQuery.isPlainObject验证。 每个键值对必须彼此相同。 不支持重命名。 仅支持字符串类型的键和值。 例: { Red: "Red", Yellow: "Yellow", Blue: "Blue" } 话虽这么说,为了实际使用枚举对象: 必须首先全局访问枚举对象。 一种方法是定义一个由普通对象组成的模块,并使其在模块名称下可用。 例如: /** * file: PrimaryColor ...
  • 枚举和普通类之间的区别主要是JVM处理枚举给你的保证。 比方说,你有一个枚举类(MyEnum)的值(VALUE1和VALUE2)。 您可以保证该枚举类的构造函数只会在您的JVM *中执行两次,当序列化和反序列化VALUE1和VALUE2时,您保证每次都获得相同的对象,这样对象相等就可以工作(但它不会用其他类保证......(例如"Foo" == new String("Foo")可能返回false)。 此外,每个枚举类都扩展了Enum>因此您可以根据需要在通用fasion ...
  • 你可能会让Animals变得可散,例如: enum Animals : Hashable { case Cow (MyCowClass) case Bird (MyBirdClass) case Pig (MyPigClass) case Chicken (MyChickenClass) var hashValue: Int { switch self { case .Cow(let v): return v. ...
  • xmlns:custom="http://schemas.android.com/apk/res/my.package.name" 是添加自定义命名空间的旧样式。 尝试使用以下内容自动替换正确的包裹 - xmlns:custom="http://schemas.android.com/apk/res-auto" xmlns:custom="http://schemas.android.com/apk/res/my.package.name" is the old style of adding a ...
  • 除了使用iota和自动枚举,或者做最直接的事情之外,没有办法: const( Stage1 FeeStage = 1 Stage2 FeeStage = 2 // or another syntax with same results Stage3 = FeeStage(2) ) 恕我直言,不如做像iota + 5这样的东西比较麻烦,正如你所说的那样非常糟糕。 如果值在程序上下文中不重要,我通常使用iota,或者如果我需要在协议或其他东西中使用值,则使用明确的键入 ...
  • 这是因为你引用的文档是边缘Rails,你可能使用Rails 4.1.0.beta1 ,这是一个测试版,而不是边缘。 4.1.0.beta1于2013年12月18日发布( https://rubygems.org/gems/rails )。 使您尝试使用的代码的提交工作从2014年1月14日开始: https : //github.com/rails/rails/commit/b242b2dbe75f0b5e86e2ce9ef7c2c5ee96e17862 并且它还具有在此提交记录之前工作的方法: + ...
  • 这真的取决于谁使用枚举。 如果它只是您自己的代码,那么您可以添加更多值而不会产生任何副作用,因为理想情况下您应该已经明确检查了预期的值。 通常很容易找到需要编辑的任何地方。 如果枚举已被释放给其他人作为API的一部分消费,那就变得更加棘手; 例如,如果将“MyNewValue”添加到用于返回Web方法的枚举中,则可能导致现有客户端(尚未更新)在发送该值时发生崩溃 - 通过代码而不是知道该怎么做,或者(更直接地)序列化层在看到它没有预料到的字符串时惊慌失措。 没有partial enum ; 只有class ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)