如何在backbone.js中展平嵌套模型?
我有一个像这样的嵌套模型:
ProgramGuide
|-channels
|-channel
|-programs
现在我想获得最后一个结束节目,无论频道如何。
在 ProgramGuide
模型中,我有一个方法:
lastProgram : function(){
//how to find last ending program?
}
那么,有没有一种好方法可以找到最后一个结束程序,也许是一种压平程序模型树的方法,或者我必须编写一个嵌套循环来实现这个?
I have a nested model like this:
ProgramGuide
|-channels
|-channel
|-programs
Now I want to get the very last ending program regardless of channels.
In the ProgramGuide
model I have a method:
lastProgram : function(){
//how to find last ending program?
}
So, is there a good way to find the last ending program, maybe a way to flatten down the model tree for programs, or must I write a nested loop to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道主干依赖于下划线,所以你总是有可用的下划线方法
我没有任何确切的代码示例,但我确信您不需要嵌套循环来运行您的结构,
我打赌您可以使用任何这些下划线方法,
我会在今天晚些时候尝试举一个例子
但我不能保证什么时候有时间。
do know that backbone depends on underscore, so you always have underscore methods available
i don't have any exact code example, but i'm sure you don't need to nest loops to run through your structure,
i bet you can use any of these underscore methods,
i will try to come up with an example, later today
but i can't promise when i have time for it.