gpt4 book ai didi

javascript - 在 Ember.js 中创建和读取记录

转载 作者:行者123 更新时间:2023-11-30 13:04:45 24 4
gpt4 key购买 nike

我正在使用 Emeber.js 框架;我创建了一个这样的对象:

myApp.user=Ember.Object.extend({
name:null,
state:false
});

我还用这种方式定义了一个 Ember 模型:

myApp.Wuser = DS.Model.extend({
nome: DS.attr('string'),
user: DS.attr('mycustomtype') // i want put here a mycustom type (user)
});

问题是:如何创建记录?我试过这样写:

myApp.Wuser.createRecord({nome:"aaa",user:myApp.user.create()});

但是发生了错误;您知道如何创建记录以及如何阅读记录吗?提前致谢!

最佳答案

您在商店中创造了一条记录。

record = this.get('store').createRecord(MyApp.User, {name: 'Luke'})

将其持久化到您的服务器:

this.get('store').commit();

您也可以为交易执行此操作:

record = transaction.createRecord(MyApp.User, {name: 'Luke'})

关于javascript - 在 Ember.js 中创建和读取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16100593/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com