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
最满意答案
枚举的一点是您创建一个只能采用固定值的新类型 。 因为在实际使用中只有很多间隔,并且因为在这里创建新类型比使用整型常量更方便,所以对于您的间隔使用枚举是合适的。
你的和弦的故事是不同的。 你已经有了和弦的类型,所以把它们包装在另一个枚举类型中是没有用的。 另外,和弦的数量远没有限制。 我手边的和弦图表显示了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.
相关问答
更多-
自定义枚举基础类型(Custom enum underlying type)[2023-02-12]
我可以定义一个类型作为枚举的基础类型吗? 您只能使用整数类型来定义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 ...
-
Json.net自定义枚举转换器(Json.net Custom enum converter)[2024-01-02]
枚举类型是ReadJson的objectType参数。 但是,有几点: 您需要处理可为空的枚举类型。 你需要处理[Flag]列举。 Json.NET将它们写成逗号分隔的值列表。 您需要处理具有无效值的枚举的情况。 Json.NET在StringEnumConverter.AllowIntegerValues == true时将它们作为数值写入,否则会引发异常。 这里是StringEnumConverter的子类,通过调用基类来处理这些情况,然后在适当的时候添加或删除类型前缀: public class Ty ... -
创建自定义枚举类型(Create Custom Enum Type)[2023-09-02]
要在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 ...
-
GO中的自定义类型的ENUM(ENUMs for custom types in GO)[2020-01-25]
除了使用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 并且它还具有在此提交记录之前工作的方法: + ...
-
扩展Enum中的功能(Extending Functionality in an Enum)[2022-12-08]
这真的取决于谁使用枚举。 如果它只是您自己的代码,那么您可以添加更多值而不会产生任何副作用,因为理想情况下您应该已经明确检查了预期的值。 通常很容易找到需要编辑的任何地方。 如果枚举已被释放给其他人作为API的一部分消费,那就变得更加棘手; 例如,如果将“MyNewValue”添加到用于返回Web方法的枚举中,则可能导致现有客户端(尚未更新)在发送该值时发生崩溃 - 通过代码而不是知道该怎么做,或者(更直接地)序列化层在看到它没有预料到的字符串时惊慌失措。 没有partial enum ; 只有class ...