最新的模型数据不会反映在网格视图中

时间:2017-09-06 15:47:47

标签: javascript backbone.js

有两个页面我们在两个视图上显示“notes”集合 - 我们使用相同的集合对象和模型对象来显示注释。如果我在另一页的一个页面上更新或修改注释,则注释集合不会获取最新数据。

如何获取和同步数据以刷新网格视图并显示最新的集合对象?

define([
   'utilsjscommon/views/BaseView',
   'utilsjscommon/views/ModalView',
   'utilsjscommon/views/grid/GridView',
   'collections/AccountNoteCollection',
   'models/AccountNoteModel',
   'views/insured/NoteModalView',
   'text!templates/insured/InsuredNoteTemplate.html'
], function (BaseView, ModalView, GridView, AccountNoteCollection, 
AccountNoteModel, NoteModalView, Template) {

var view = BaseView.extend({
template: _.template(Template),

events: {
  'click button.new-note': 'newNote',
  'click button.delete-note': 'deleteNote',
  'click button.edit-note': 'editNote'
},

init: function () {
  this.noteGrid = new GridView({
    collectionClass: AccountNoteCollection,
    gridStyle: 'condensed',
    perPage: 8,
    defaultSort: ['enteredon|desc'],
    columns: {
      note: {
        href: true
      },
      enteredby: { header: 'entered by' },
      enteredon: {
        header: 'entered on',
        type: 'date'
      }
    },
    paginationStyle: 'small',
    maxPageControl: 3,
    multiSelect: false
  });
    this.model.bind('reset', this.render, this);
  this.subviews.push(this.noteGrid);
},

render: function () {
  this.$el.html(this.template());

  this.listenTo(this.noteGrid, 'resetControls', this.resetNoteControls);
  this.$('#ud_noteGrid').html(this.noteGrid.render().el);
    return this;
},

refresh: function () {
  this.getNotes();

},


getNotes: function () {
    this.noteGrid.fetch({
        insuredid: this.model.get('insuredid')
    });
},

0 个答案:

没有答案