构建ember-data需要Ruby 1.9.在MacOS Mountain Lion上安装这个版本的Ruby并不是一项微不足道的任务,所以我并不热衷于尝试这一点.我想知道是否有其他人可以为我执行此构建并向我发送构建的包.我目前正在尝试使用的版本是版本4,与存储库中的最新版本完全不同.
有没有人知道最近是否存在camelcased属性的问题.
我有这样的模型:
var attr = DS.attr;
App.Users = DS.Model.extend({
firstName: attr('string'),
phone: attr('string'),
email: attr('string')
});
Run Code Online (Sandbox Code Playgroud)
在我的模板中,电子邮件和手机显示正确,但firstName没有出现.我检查了json文件,一切似乎都没问题.我的所有其他模型出现相同的问题,所以我想它必须与camelCase做一些事情.
我正在尝试执行以下操作:
App.Availablephone.all().forEach(function(phone, index) {
phone.unloadRecord();
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,由于.all()是一个实时数组,这不起作用(数组在循环期间被修改,并完全混淆).
如何从商店卸载特定类型的所有记录?
我正在从EMber数据0.13迁移到1.0.0 beta.根据文档(https://github.com/emberjs/data/blob/master/TRANSITION.md),以下内容应该有效:
App.AuthorsNewRoute = Ember.Route.extend({
model: function () {
return this.store.createRecord('author');
},
actions: {
save: function() {
this.modelFor('author').save();
}
}
})
Run Code Online (Sandbox Code Playgroud)
但是,在我的情况下,我总是得到一个"无法调用方法'保存'未定义"错误".
使用" this.get(' currentModel '). save();"时,它在路径中使用保存操作时有效.将保存操作放入控制器时,它不再起作用.相同的错误:无法调用未定义的"保存"方法错误.
如何在控制器中访问新创建的记录并保存?
有人可以提供一个简单的例子吗?
马克斯
我已经基于这篇文章实现了身份验证
因此我App.Session在应用程序初始化时创建一个对象
Ember.Application.initializer({
name: 'session',
initialize: function (container, application) {
App.Session = Ember.Object.extend({
init: function () {
this._super();
this.set('authToken', $.cookie('auth_token'));
this.set('authAccountId', $.cookie('auth_accountId'));
this.set('authAccountLanguage', $.cookie('auth_accountLanguage'));
},
authAccountIdChanged: function () {
var authAccountId = this.get('authAccountId');
$.cookie('auth_accountId', authAccountId);
//Load the actual account record from the server if the authAccountId is set
//Used to have for example the full name or other properties of the account
if (!Ember.isEmpty(authAccountId)) {
this.set('authAccount', this.store.find('account', authAccountId));
}
}.observes('authAccountId'),
...
Run Code Online (Sandbox Code Playgroud)
我有观察员authAccountId; 因此,每次accountId …
我有以下Ember.js模型:
Filters.Milestone = DS.Model.extend({
id: DS.attr('string'),
name: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
在我的app.js中,我对模型进行了以下设置(在模型之前加载):
Filters.MilestoneSerializer = DS.RESTSerializer.extend();
Filters.MilestoneAdapter = DS.RESTAdapter.extend({
namespace: "ember"
});
Run Code Online (Sandbox Code Playgroud)
加载页面时,将完成对里程碑列表的AJAX调用.返回以下JSON:
{
"milestones": [
{
"id": "1",
"name": "Test Milestone #1"
}
]
}
Run Code Online (Sandbox Code Playgroud)
加载JSON时,将返回以下错误:
TypeError: Cannot call method 'hasOwnProperty' of undefined
at e (http://sandbox.local/ember/js/libs/ember-data.js:8:30934)
at null.<anonymous> (http://sandbox.local/ember/js/libs/ember-data.js:8:31181)
at ComputedPropertyPrototype.set (http://sandbox.local/ember/js/libs/ember-1.4.0.js:4903:18)
at new Class (http://sandbox.local/ember/js/libs/ember-1.4.0.js:12652:18)
at Function.Mixin.create.create (http://sandbox.local/ember/js/libs/ember-1.4.0.js:13104:12)
at Ember.Object.extend.buildRecord (http://sandbox.local/ember/js/libs/ember-data.js:10:2880)
at Ember.Object.extend.recordForId (http://sandbox.local/ember/js/libs/ember-data.js:9:31214)
at Ember.Object.extend._load (http://sandbox.local/ember/js/libs/ember-data.js:10:2048)
at Ember.Object.extend.push (http://sandbox.local/ember/js/libs/ember-data.js:10:2450)
at null.<anonymous> (http://sandbox.local/ember/js/libs/ember-data.js:10:2701)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我尝试使用与https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/adapter/rest_adapter_test.js#L465相同的结构.如果我重命名里程碑键,它说没有找到新键的模型,所以必须是正确的:-)
提前致谢.
我使用的路线如下:
Filters.FiltersRoute = …Run Code Online (Sandbox Code Playgroud) 我有一个Ember-cli应用程序(v2.1),当我从我的博客模型中删除记录时,我遇到了Ember Data的问题.这是我要求删除的代码:
deleteBlog (blog) {
this.store.findRecord('blog', blog.get('id')).then(blog => {
blog.destroyRecord();
});
}
Run Code Online (Sandbox Code Playgroud)
正如所料,Ember Data发出了DELETE请求,它与我的express.js后端服务完美配合.
该唯一的问题是,记录不会被从灰烬数据存储中移除,而我得到以下错误信息:
错误:pushedData在状态root.deleted.inFlight中尝试在my-app @ model上处理事件:blog :: ember529:56455037f9cf29a325ae72b9
我感谢任何反馈!
我的Spring后端有一个JSON对象.如何在Ember应用程序商店中创建数据对象?
我试过了:
createObject() {
var _this = this;
$.getJSON('http://localhost:8080/object/getCard?id=24').then(function(response) {
_this.store.createRecord('cards/object/card', response);
});
}
Run Code Online (Sandbox Code Playgroud)
JSON:
{
"id":24,
"fullName":"qwerty",
"form":"zzzzzzzzzzzz",
"leader": {
"id":23,
"fullName":"testName test",
"email":"emailTest"
}
}
Run Code Online (Sandbox Code Playgroud)
我在Ember应用程序中有一个模型
export default DS.Model.extend({
fullName: DS.attr('String'),
form: DS.attr('String'),
leader: DS.belongsTo('contact', { async: true })
}
Run Code Online (Sandbox Code Playgroud)
和联系方式:
export default DS.Model.extend({
fullName: DS.attr('String'),
email: DS.attr('String')
});
Run Code Online (Sandbox Code Playgroud) 这是我的样本下拉菜单
<select name="newType" class="parts-select full-width-combo" onchange={{action "loadFilter" value="target.value" }}>
<option value="" selected hidden >Select </option>
{{#each model as |item|}}
<option value="{{item.id}}">{{item.description}}</option>
{{/each}}
</select>
Run Code Online (Sandbox Code Playgroud)
从相关模板操作我想动态设置此选定项目.
例如,它默认选择"选择",然后根据该页面上的某个按钮单击,并需要将我选择的选项设置为其他选定的选项.我没有使用任何插件,我不能在这里做.
我对Ember的文档中的queryParams感到困惑.它表明您可以将queryParams放到Controller或Route.除了语法之外,在Route vs Controller中有queryParams有什么区别?
据我所知,在Route中将queryParams作为对象允许我做以下事情:
在什么情况下你会选择在Controller中使用queryParams?