我正在尝试迁移一个ember应用程序来使用ember app-kit.该代码需要accounting.js库.在pre-app-kit版本中,文件是通过脚本标签加载的index.html
<script src="http://cdnjs.cloudflare.com/ajax/libs/accounting.js/0.3.2/accounting.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
并通过全局命名空间在视图中访问
App.MoneyField= Em.TextField.extend({
init: function() {
this._super();
var value = accounting.formatMoney(this.get("money") / 100, '');
this.set('value', value);
};
// other functions omitted
});
Run Code Online (Sandbox Code Playgroud)
在app-kit版本中,我将其accounting.js作为一个凉亭依赖项包含在内.在bower.json:
{
"name": "ember-app-kit",
"dependencies": {
"handlebars": "~1.1.2",
"jquery": "~1.9.1",
"qunit": "~1.12.0",
"ember": "~1.4.0-beta.2",
"ember-data": "~1.0.0-beta.6",
"ember-resolver": "git://github.com/stefanpenner/ember-jj-abrams-resolver.git#master",
"ic-ajax": "~0.3.0",
"ember-testing-httpRespond": "~0.1.1",
"accounting":"~0.3.2"
},
"resolutions": {
"ember": "~1.4.0-beta.2"
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试构建应用程序时,它会给出错误
W117: 'accounting' is not defined.
Run Code Online (Sandbox Code Playgroud)
我明白为什么会这样,并知道我需要某种import accounting from ...陈述.
如何将通过bower安装的软件包导入为ES6模块?
我在注册后为用户设置了自动身份验证:
应用程序/库/自动authenticate.js
export default Ember.SimpleAuth.Authenticators.OAuth2.extend({
authenticate: function(credentials) {
if(!Ember.isEmpty(credentials.access_token)) {
return Ember.RSVP.resolve(credentials);
} else {
return this._super(credentials);
}
}
});
Run Code Online (Sandbox Code Playgroud)
应用程序/ app.js
import AutoAuthenticate from 'appkit/libs/auto-authenticate';
App.initializer({
name: 'auto',
initialize: function(container, application) {
container.register('app:authenticators:custom', AutoAuthenticator);
Ember.SimpleAuth.setup(container, application);
}
});
Run Code Online (Sandbox Code Playgroud)
应用程序/控制器/ register.js
export default Ember.ObjectController.extend({
firstname: '',
lastname: '',
username: '',
password: '',
actions: {
registerUser: function(){
var self = this;
var user = this.store.createRecord('user', {
first_name: this.get('firstname'),
last_name: this.get('lastname'),
username: this.get('username')
});
user.set('typedPass', this.get('password'));
user.save().then(function(){
//How can I login this …Run Code Online (Sandbox Code Playgroud) 试图试驾我的第一个ember.js应用程序.使用ember app kit.
qunit如何与选择器一起使用感到困惑(我假设jquery选择器可以工作,而且它们确实在 - 大部分......).
我的车把有这个代码:
{{#link-to 'locations.new' classNames='add-btn'}}
Add new location
{{/link-to}}
Run Code Online (Sandbox Code Playgroud)
我打算测试是否存在适当的链接,href并单击链接并在点击后验证当前的URL和路由.
所以,我的测试如下:
// There is an element that links to locations/new
var link = find('a[href="#/locations/new"]');
ok(link, 'There is a link to add new location on the page');
click(link);
andThen(function() {
equal(currentRouteName(), 'locations.new', 'Clicked "add" button - now locations.new route is active');
equal(currentURL(), '/locations/new', 'Clicked "add" button - and current url is /locations/new');
});
Run Code Online (Sandbox Code Playgroud)
注意:我使用currentRouteName和currentURL助手从这个PR的EAK,和他们像预期的那样.
我的测试失败click(link)了Error: …
我已经开始使用ember app kit并通过其指南阅读.然而,我无法解决常规应用程序之间的差异,这样Ember App Kit使用ES6模块构建各种位,而不是将所有内容填充到用作命名空间的全局变量(例如App).
我发现这方面的解释不是很清楚:
非常感谢提前!
编辑(20140506):
这些资源很好地解释了ES6模块和EAK:
我正在尝试使用ember app kit和使用ES6的ember数据开始一个新项目.我已经设法使用以下代码创建商店adapter.js
var ApplicationAdapter = DS.FixtureAdapter.extend();
export default ApplicationAdapter;
Run Code Online (Sandbox Code Playgroud)
但是,我无法创建模型并访问它.在models/account.js我有这个
var Account = DS.Model.extend({
name: DS.attr('string')
});
Account.FIXTURES = [
{
'id': 1,
'name': 'Acc 1'
}, {
'id': 2,
'name': 'Acc 2'
}
]
export default Account;
Run Code Online (Sandbox Code Playgroud)
在我的routes/accounts.js我有这个:
var AccountsRoute = Ember.Route.extend({
model: function() {
var store = this.get('store');
return store.find('account');
}
});
export default AccountsRoute;
Run Code Online (Sandbox Code Playgroud)
在这个阶段,我只是想从屏幕上显示的灯具中获取一个帐户列表.路由很好,如果我输入静态数据(如索引路由),那么一切正常.但是,使用上面的代码,我遇到了麻烦
DEPRECATION: Action handlers contained in an `events` object are deprecated in favor of putting …Run Code Online (Sandbox Code Playgroud) 保持简短:
是否可以Resolver在Ember.Application.create()块外设置应用程序?
理想情况下,我想设置Resolver一个Ember.Application.initializer#initialize()函数.就像是:
import CustomResolver from 'appkit/utils/resolver/custom';
import CustomAjax from 'appkit/utils/ajax/custom';
Ember.Application.initializer({
name: 'resolver_setup',
initialize: function (container, application) {
// NOTE: For an unknown reason (unknown to me!) I can't import CustomAjax in CustomResolver...
application.set('Resolver', CustomResolver.create({ajax: CustomAjax.create({})});
}
});
Run Code Online (Sandbox Code Playgroud)
这可能吗?
PS:我需要自定义解析器的原因是,我从服务器获取所有模板,而不是在应用程序启动时将它们提供给用户.因此,我正在扩展ember-jj-abrams-resolverEAK中默认使用的...
我正试图在我的ember项目中使用ember app kit作为构建工具/项目结构.但无论我尝试什么样的ember app kit的解析器都无法找到我的部分.
未捕获的错误:找不到部分公司/编辑注释
我的部分是在子文件夹中,即:
company/_edit-note.emblem
然后我尝试以多种方式使用emblems语法加载部分:
> company/edit-note
> "company/edit-note"
> company/_edit-note
> "company/_edit-note"
Run Code Online (Sandbox Code Playgroud)
我也尝试不嵌套部分但具有相同的结果.
我在ember app kits repo https://github.com/stefanpenner/ember-app-kit/issues/244上注意到了这个问题,并尝试用前缀hyphen而不是下划线来命名我的partials,但无济于事.
我查看了Ember.TEMPLATES,无论命名约定如何,我都看到模板完整路径,即公司/ _edit-note.
任何帮助将不胜感激.
当我想在我的项目中复制ember-app-kit-master文件时,我执行
cmd: cd C:\Users\hp-pc\Desktop\MyApp
Run Code Online (Sandbox Code Playgroud)
然后
cmd: npm install
Run Code Online (Sandbox Code Playgroud)
但是我遇到了一些错误:
npm ERR! not found: git
npm ERR!
npm ERR! Failed using git.
npm ERR! This is most likely not a problem with npm itself.
npm ERR! Please check if you have git installed and in your PATH.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "G:\\Publish\\nodeJs\\\\node.exe" "G:\\Publish\\nodeJs\\node_mo
dules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\Users\hp-pc\Desktop\MyApp
npm ERR! node -v v0.10.24
npm ERR! npm -v 1.3.9
npm ERR! code ENOGIT
Run Code Online (Sandbox Code Playgroud)
这是我的package.json的一部分:
"repository": …Run Code Online (Sandbox Code Playgroud) 在Ember App Kit中,有许多测试示例随初始回购一起提供.其中之一是基本的路线单元测试.如果数据在模型钩子中是硬编码的,那么这个测试是微不足道的,如下所示:
test("#model", function(){
deepEqual(route.model(), ['red', 'yellow', 'blue']);
});
Run Code Online (Sandbox Code Playgroud)
如果它从ember-data返回一个promise,你如何使用隔离容器来测试模型钩子?
这是测试:
import Activities from 'appkit/routes/activities';
var route;
module("Unit - ActivitiesRoute", {
setup: function(){
var container = isolatedContainer([
'route:activities'
]);
route = container.lookup('route:activities');
}
});
test("#model", function(){
deepEqual(route.model(), ['activity', 'activity2', 'activity3']);
});
Run Code Online (Sandbox Code Playgroud)
而实际的Route的模型钩子:
export default Ember.Route.extend({
model: function() {
return this.get('store').find('activity');
}
});
Run Code Online (Sandbox Code Playgroud)
从kingpin2k实施以下不同方法后.以下是结果摘要.
第一种方法:效果很好......但没有承诺.
第二种方法:返回promise对象(似乎已解析),但数组和正确的值被赋给_detail属性.
test("#model", function(){
deepEqual(route.model()['_detail'], ['activity', 'activity2', 'activity3']); //passes
});
Run Code Online (Sandbox Code Playgroud)
我想在模块设置()中处理商店创建.
...
module("Unit - ActivitiesRoute", {
setup: function(){
var container = isolatedContainer([
'route:activities' …Run Code Online (Sandbox Code Playgroud) ember.js ×8
ecmascript-6 ×2
ember-data ×2
javascript ×2
bower ×1
jquery ×1
qunit ×1
testing ×1