我正在寻找一种将焦点设置为文本字段或文本区域的简单方法.我不喜欢将Jquery语法与Ember语法混合使用......我宁愿不为每个我想设置焦点的textfield或textarea创建单独的视图.
有什么建议 ?
我的textArea字段很简单:
{{view Ember.TextArea valueBinding="body" placeholder="body"}}
Run Code Online (Sandbox Code Playgroud)
谢谢马克
我正在转换一个项目,用于Ember数据1.0.0 Beta 1(刚刚发布).我有一个REST适配器侦听特定端点,因此需要自定义端点.
这是它在Ember数据0.13中的工作方式:
App.Adapter = DS.RESTAdapter.extend({})
DS.RESTAdapter.reopen({
url: 'https://api.example.com'
});
Run Code Online (Sandbox Code Playgroud)
在Ember数据0.13中,URL变为: https://api.example.com/authors
在Ember数据1.0.0中,网址变为: http://192.168.0.108:51939/authors
使用/192.168.0.108:51939运行webapp的URL.
因此看起来RESTAdapter的.reopen上的url设置不再有效?
我对URL的其他自定义(例如命名空间)有同样的问题...
希望有人可以提供帮助.
渣
见JSFiddle:http://jsfiddle.net/cyclomarc/HKHEJ/2/
我正在从Ember数据0.13转换为1.0.0 beta.在以前的版本中,您可以使用transaction.rollback()来还原模型中所做的任何更改(尚未保存).
在1.0.0中,您可以使用record.rollback().我遇到的问题是当时所有属性都被清除了......
cancel: function () {
var author = this.get('model');
author.rollback();
},
Run Code Online (Sandbox Code Playgroud)
JSFiddle中的场景:单击名称,更改其中一个文本域中的文本,然后单击"还原更改".除id之外,所有字段都被清除.
这是一个已知的问题 ?
我有以下型号:
App.Publication = DS.Model.extend({
title: DS.attr('string'),
bodytext: DS.attr('string'),
author: DS.belongsTo('author')
});
App.Author = DS.Model.extend({
name: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
以下是json数据:
{
"publications": [
{
id: '1',
title: 'first title',
bodytext: 'first body',
author_id: 100
},
{
id: '2',
title: 'second title',
bodytext: 'second post',
author_id: 200
}
];
}
Run Code Online (Sandbox Code Playgroud)
在Ember Data RC12中,这有效(您可以在json中指定author_id或作者,并且出版物将始终链接正确的作者).
在Ember Data 1.0.0中,这不再有效; 作者总是空的.
在一些文档中,我发现 - 因为我在json数据中使用"author_id"(而不仅仅是作者) - 我需要在模型中指定键; 从而:
author: DS.belongsTo('author', { key: 'author_id' })
Run Code Online (Sandbox Code Playgroud)
然而,这不起作用; 该出版物中的作者仍为空.
我现在看到的唯一解决方案是实现自定义序列化程序并将author_id覆盖为author(通过normailzeId); 我无法改变我的后端数据结构...因此:
App.MySerializer = DS.RESTSerializer.extend({
//Custom serializer used for all models
normalizeId: …Run Code Online (Sandbox Code Playgroud) 我只想更改从夹具适配器获取数据到REST适配器.我在文档中找不到正确的语法...无论我尝试什么,都不会对REST接口执行JSON调用.
有人可以帮忙吗?
PS.当我只使用JQuery调用(return $.getJSON('http://localhost:3000/articles.json');)时,这是有效的,但如上所述,我想使用Ember REST适配器...
我的模特:
App.Article = DS.Model.extend({
title: DS.attr('string'),
author: DS.attr('string'),
body: DS.attr('string')
});
Run Code Online (Sandbox Code Playgroud)
我的修复适配器:
App.Store = DS.Store.extend({
revision: 12,
adapter: 'DS.FixtureAdapter'
});
Run Code Online (Sandbox Code Playgroud)
我的REST适配器(不工作)
App.Store = DS.Store.extend({
revision: 12,
adapter: DS.RestAdapter.create({
url: 'http://localhost:3000'
})
});
Run Code Online (Sandbox Code Playgroud)
我的路线
App.ArticleRoute = Ember.Route.extend({
model: function () {
App.Article.find();
//return $.getJSON('http://localhost:3000/articles.json');
}
});
Run Code Online (Sandbox Code Playgroud) 我已在ES集群上安装了针对Elasticsearch的智能中文分析,但我找不到有关如何指定正确分析器的文档.除了我需要设置一个tokenizer和一个指定停用词和词干分析器的过滤器...
例如在荷兰语中:
"dutch": {
"type": "custom",
"tokenizer": "uax_url_email",
"filter": ["lowercase", "asciifolding", "dutch_stemmer_filter", "dutch_stop_filter"]
}
with:
"dutch_stemmer_filter": {
"type": "stemmer",
"name": "dutch"
},
"dutch_stop_filter": {
"type": "stop",
"stopwords": ["_dutch_"]
}
Run Code Online (Sandbox Code Playgroud)
如何为中文配置我的分析仪?
我想在Ember应用程序中使用TinyMCE组件.我的基本问题是:你如何以及在哪里提出这个问题?
模板包含textarea元素:
<textarea class='test' name="content" style="width:100%">
Run Code Online (Sandbox Code Playgroud)
我需要按如下方式初始化TinyMce:
tinymce.init({
selector: "textarea"
});
Run Code Online (Sandbox Code Playgroud)
我在哪里需要做init以及如何做?在控制器init中思考,但这不能按预期工作...
App.IndexController = Ember.Controller.extend({
init: function() {
tinymce.init({
selector: "textarea"
});
}
});
Run Code Online (Sandbox Code Playgroud)
见JSFiddle:http://jsfiddle.net/cyclomarc/wtktK/6/
希望有人能帮忙......
请参阅:http://jsfiddle.net/cyclomarc/36VS3/1/
我正在使用Ember i18n lib进行翻译.如何在Ember.TextField视图中使用已翻译的字符串?
同意textarea视图和选择视图.
<script type="text/x-handlebars">
<h2>Ember Translate placeholder</h2>
{{t T1005}}<br>
{{view Ember.TextField placeholder="T1005"}}
</script>
Run Code Online (Sandbox Code Playgroud)
输入字段中的占位符也应该说'Info',因此不是'T1005'(作为字符串的引用).
如果路由存在,路由器会很好地处理URL并导致调用适当的路由.但是如何处理路径不存在的情况?
app.js
App = Ember.Application.create();
App.Router.map(function () {
this.resource('about', { path: "/about" });
this.resource('admin', { path: "/admin" });
});
Run Code Online (Sandbox Code Playgroud)
的index.html
<script type="text/x-handlebars" id="about">
<h1>ABOUT</h1>
</script>
<script type="text/x-handlebars" id="admin">
<h1>ADMIN</h1>
</script>
Run Code Online (Sandbox Code Playgroud)
使用案例:
当用户输入URL index.html#/ xxxx时,我想转换到一种错误页面,指示所请求的"页面"不会退出.
到目前为止,我没有找到解决方案......
当您从index.html#/ admin/authors/1/edit转换为index.html#/ admin/authors/2/edit时,不会调用路由上的deactivate .
当您从index.html#/ admin/authors/1/edit转换为index.html#/ admin/authors/new时,将调用路由上的deactivate .
我希望在两种情况下都可以调用deactivate?
在路由级别是否有另一种方法来检测您是否从../1/edit切换到../2/edit?
我需要在主详细信息视图中显示(master是所有作者的列表,详细信息是包含每个作者属性的文本字段的表单).如果用户在列表中选择了另一位作者而前一位作者未经保存而被修改,我需要回滚该事务或询问用户"你想保存更改吗?".
我正在从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 …
我在Elastic Search中使用父子文档。我可以使用_update API对主文档进行部分更新。但是,如果我在子文档上使用_update APi,则文档的内容将完全替换为脚本内容。出问题了...我不知道什么....
请参见下面的示例:
创建儿童文件
POST to /indexName/comment/c006?parent=b003
{
"authorId": "ps101",
"authorFullName": "Lieven",
"body": "Comment text comes here",
"isApproved": false
}
Run Code Online (Sandbox Code Playgroud)
获得孩子
GET to /indexName/comment/c006?parent=b003
{
_index: "indexName"
_type: "comment"
_id: "c006"
_version: 20
found: true
-_source: {
authorId: "ps101"
authorFullName: "Lieven"
body: "Comment text comes here."
isApproved: false
}
}
Run Code Online (Sandbox Code Playgroud)
部分更新
POST TO /indexName/comment/c006?parent=b003/_update
{
"script" : "ctx._source.isAcceptedAnswer=value",
"params" : {
"value" : true
}
}
Run Code Online (Sandbox Code Playgroud)
现在,重新与孩子
GET to /indexName/comment/c006?parent=b003
{
_index: "indexName"
_type: "comment"
_id: "c006"
_version: …Run Code Online (Sandbox Code Playgroud)