我目前正在开发一个主干应用程序,它可以与API进行“对话”。用户可以编辑组织例如,补丁请求将去往API并被保存到数据库,在成功时API然后通过这条线路与推送器“对话”,
Pusherer::trigger('organisation_'.$id, 'organisation:change', json_encode(array('organisation' => $organisation)));
基本上,这告诉推动器在organisation_21通道上触发一个事件,已经发生的事件是组织:更改一个,而要发送的数据是组织模型。
然后在主干端发生的事情是,我将一个方法绑定到该通道上,当事件发生时,该方法将运行,并更新订阅用户的视图。
然而,我的组织的数据变得相当大,JSON对象是11.8kb,pusher不会处理超过10kb的任何东西,除了发送整个模型之外,有没有更好的方法来处理backbone、我的api和pusher?
关于建议,我喜欢这个想法,做保存,并通过pusher实时获取新数据的模型。是不是像这样?
organisationChanged:function(){
var self = this;
this.model.get('organisations').fetch({ //send GET To /api/organisation/id
success: function(model, response) {
self.model.get('organisations').set(response);
}
});
}获取模型并将从服务器返回的属性设置为模型的属性-到目前为止,我认为这听起来是正确的,是吗?复杂的是,模型还包含几个集合,将在这些集合上设置工作,还是有更好的方法?
发布于 2015-07-02 01:01:22
编辑是正确的想法,但有一些小的变化。fetch会自动更改模型。从您的代码看,您的模型是一个更大的模型,而组织只是一个子模型。如果是这样的话:
var organizationmodel=this.model.get('organisations') // This would get the organization model.
organizationmodel.fetch({ //send GET To /api/organisation/id
success: function(model, response) {
// the model, and the organizationmodel both actually should point to the same object
// and they are already changed based on the server returned stuff. so no need to do a set.
// if they are not, you can just set it again.
self.model.set('organizations',model);
}
});https://stackoverflow.com/questions/31165710
复制相似问题