小编Fré*_*aro的帖子

deleteRecord后列表未更新

我有一个ArrayController,其内容在这样的路由中定义:

App.UsersRoute = Ember.Route.extend({
  model: function() {
    return App.User.find();
  },

  setupController: function(controller, model) {
    this._super(controller, model);
    this.controllerFor('application').set('currentRoute', 'users');
  }
});
Run Code Online (Sandbox Code Playgroud)

我在模板中列出数据:

<ul>
  {{#each user in arrangedContent}}
  <li>
    {{user.lastName}} {{user.firstName}}
    {{#linkTo "users.edit" user class="btn btn-primary btn-small"}}EDIT{{/linkTo}}
  </li>
  {{/each}}
</ul>
Run Code Online (Sandbox Code Playgroud)

它工作正常.

如果我创建一个新项目,它会自动添加到模板中的列表中:

App.UsersNewRoute = Ember.Route.extend({
  model: function() {
    return App.User.createRecord({firstName: '', lastName: ''});
  }
});
Run Code Online (Sandbox Code Playgroud)

但是当我在"编辑"视图中删除某个项目时,它不起作用:

App.UsersEditController = Ember.ObjectController.extend({
  ...

  destroy: function() {
    this.get('content').deleteRecord();
    this.get('store').commit();
    this.transitionToRoute("users.index");
  }
});
Run Code Online (Sandbox Code Playgroud)

但是在"新"视图中,如果我删除了新创建的项目,它就可以工作(没有提交).

在编辑控制器中,如果我删除"提交",则列表会更新,但当我执行其他操作时,将重新加载列表,并重新显示已删除的项目(正常).

那么,如何删除项目?

注意:我使用ember和ember-data的"master"代码,刚刚刷新.

ember.js ember-data

13
推荐指数
1
解决办法
5183
查看次数

“属性'X'的类型不兼容”但不是

我试图创建一个接口对象,其属性从另一个对象初始化,如下所示:

id: data.reference.id
Run Code Online (Sandbox Code Playgroud)

属性是兼容的,但 typescript 编译器会引发错误。我不明白为什么以及如何避免这个错误。

(后面可以找到测试代码的链接)

// INTERFACES AND TYPES
type CategoryOne = 1
type CategoryTwo = 2
type Category = CategoryOne | CategoryTwo

interface ReferenceOne {
    id: string,
    type: CategoryOne
}

interface ReferenceTwo {
    id: string,
    type: CategoryTwo
}

type Reference = ReferenceOne |  ReferenceTwo

// DIRECT INIT
let reference_OK: Reference = { // works here
    id: '1',
    type: 1
}

// INIT FROM DATA
interface Data {
    reference: {
        id: string,
        type: Category
    }
}

let data: …
Run Code Online (Sandbox Code Playgroud)

typescript

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

ember-data ×1

ember.js ×1

typescript ×1