如何更改backbone.js应用程序中的Firebase URL

时间:2016-03-15 14:04:00

标签: backbone.js firebase backbonefire

我正在创建一个分为几个月的骨干应用程序。 在我的firebase中,月份是父节点,在此之下我有我需要的键\值对。

我无法弄清楚如何更改月份并触发所有更新。 例如,如果我硬编码我的网址就像

https://blinding-fire-XXXX.firebaseio.com/Application/Month1

这对于获取Month1的数据很好,但是如何更新我的应用程序以获取Month2的数据?

我假设我应该能够使用基本网址(没有Month1)和某种过滤器,但我无法弄明白。

我尝试过,当用户选择另一个月时“重新启动”该应用,这会在第一次显示一个月时有效,但如果他们返回到之前选择的月份,我会得到一个空列表。

希望有人能指出我正确的方向!

1 个答案:

答案 0 :(得分:0)

You can use the urlRoot property根据基本网址和模型的Firebase.Model创建新的id

var Month = Backbone.Firebase.Model.extend({
  urlRoot: 'https://<my-firebase>.firebaseio.com/Application/'
});

// The url for this model is https://<my-firebase-app>.firebaseio.com/Application/Month1
var month = new Month({
  id: "Month1"
});

month.on('sync', function(model) {
  console.log('Model loaded');
  console.log(model)'
});