我有一个控制器,有一个searchQuery和建议属性.建议来自AJAX请求.如何在控制器中将建议属性作为承诺?
app/controllers/application.js
import Ember from 'ember';
const { computed, $ } = Ember;
export default Ember.Controller.extend({
searchQuery: '',
suggestions: computed('searchQuery', function() {
return $.getJSON(`songs/search.json?q=${this.get('searchQuery')}`);
})
});
Run Code Online (Sandbox Code Playgroud) 在您首先编写的新ember应用程序中:
var App = Ember.Application.create({
test: 'foo',
...
});
Run Code Online (Sandbox Code Playgroud)
在您首先编写的新ember-cli应用程序中:
var App = Ember.Application.extend({
test: 'foo',
...
});
Run Code Online (Sandbox Code Playgroud)
为什么?
(在第二种情况下,我无法从控制器读取全局属性(App.test).!?)
我一直在尝试将生产模式中的ember-cli应用程序部署到nginx服务器上.我已经回顾了ember-cli文档并查看了其他类似的问题,例如(如何在github页面上部署使用ember-cli开发的Ember.js应用程序?) - 这些似乎表明在/中设置ENV.baseURL变量app/config/environment.js应解决问题,但我找不到适合我的值.
生成的文件ember build --environment production位于/ Users/gordon/src/app/dist
nginx配置看起来像:
server {
listen 4200 ssl;
server_name localhost;
ssl_certificate /Users/gordon/src/app/server.crt;
ssl_certificate_key /Users/gordon/src/app/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
root /Users/gordon/src/app/dist/;
location / {
# index index.html;
try_files $uri $uri/ /index.html?/$request_uri;
}
}
Run Code Online (Sandbox Code Playgroud)
在Users/gordon/src/app/config/environment.js中如果我将ENV.baseURL保留为默认值,我会在浏览器控制台中显示以下错误...
Uncaught TypeError: undefined is not a function vendor-70567c507a348c9884b7aba3ccaae1fd.js:14
Uncaught ReferenceError: DS is not defined
Run Code Online (Sandbox Code Playgroud)
...如果我将它设置为/ Users/gordon/src/app /,/ Users/gordon/src/app/dist /或/ Users/gordon/src/app/dist我得到
Uncaught SyntaxError: Unexpected token < :4200/Users/gordon/src/sellthru/dist/assets/vendor-70567c507a348c9884b7aba3ccaae1fd.js:1
Uncaught SyntaxError: Unexpected token < :4200/Users/gordon/src/sellthru/dist/assets/sellthru-app-4b7e6077c7df38b31e70e32056d7d7aa.js:1
Uncaught …Run Code Online (Sandbox Code Playgroud) 我正在制作一个有/admin路线的Rails引擎.我想用Ember CLI创建这个管理界面.
我知道rails会自动预编译生活在我的引擎lib目录中的任何静态JS/CSS ,并且只在父应用程序挂载我的引擎并访问该路由时才加载它们.但是,我想使用Ember CLI来构建管理界面.
这样做有什么好办法?理想情况下,我希望将Ember CLI构建保留在repo之外.
只是说我创建了一个与其他用户共享的插件,我需要导入ember-data.
import DS from 'ember-data';
Run Code Online (Sandbox Code Playgroud)
如果它可能不存在于客户端代码中,我该如何导入它.基本上我需要一个条件来检查ember-data是否可用,如果是这样导入并执行某些操作,否则不要这样做.
if(ember data exists) {
//do something
}
Run Code Online (Sandbox Code Playgroud) 在构建仅用于生产时,是否可以从ember-cli中的vendor.js中排除jQuery依赖项?我想在我的网站中单独包含它.
我正在获得一个POST https://heroku_client_path.herokuapp.com/login 405 (Not Allowed)带有Rails api的Ember.js应用程序(两者都在heroku上)
处理登录或注册时.我觉得请求URL应该是heroku服务器路径/登录,因为我设置了我的ADAPTER_URLheroku配置var,而不是上面显示的heroku客户端URL.
我相信我已正确设置CORS.
我正在使用Ember-CLI.我用手滚动认证它不是Simple-Auth.
environment.js:
module.exports = function(environment) {
var ENV = {
modulePrefix: 'client-rantly',
environment: environment,
baseURL: '/',
adapterURL: process.env.ADAPTER_URL,
locationType: 'auto',
EmberENV: {
FEATURES: {
}
},
};
if (environment === 'development') {
}
if (environment === 'production') {
}
return ENV;
};
Run Code Online (Sandbox Code Playgroud)
适配器/ application.js中:
import DS from 'ember-data';
import ENV from '../config/environment';
export default DS.ActiveModelAdapter.extend({
host: ENV.adapterURL || ENV.ADAPTER_URL,
headers: function () {
return {
'auth_token': localStorage.getItem('authToken')
}; …Run Code Online (Sandbox Code Playgroud) 我正在构建一个相对直接的comment-list组件.我想传递可评论的模型(比如说a Post)并让组件负责创建,编辑和删除注释.现在我传递了各种各样的动作,而且非常脆弱.
如何在组件集成测试中创建Ember Data模型的真实实例?
我的直接想法是导入模型然后.create({})它,但错误use this.store.createRecord() instead
/* jshint expr:true */
import { assert } from 'chai';
import { describeComponent, it } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import Post from 'ownersup-client/post/model';
describeComponent( 'comment-list', 'Integration: CommentListComponent', {
integration: true
},
function() {
it('renders all of the comments', function() {
const model = Post.create({ title: 'title' });
model.get('comments').createRecord({ body: 'One Comment' })
this.render(hbs`{{comment-list model=model}}`);
assert.lengthOf(this.$('.comment-list-item'), 1);
});
}
);
Run Code Online (Sandbox Code Playgroud)
有人有什么想法?
我有两个嵌套这样的路线.
router.js
this.route('profile', function() {
this.route('edit');
});
Run Code Online (Sandbox Code Playgroud)
像这样的这些路线的几个导航栏链接..
navbar.hbs
{{#link-to 'profile' tagName="li"}}<a href>View Profile</a>{{/link-to}}
{{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/link-to}}
Run Code Online (Sandbox Code Playgroud)
该link-to助手添加active类到li这里的标签.因此,当我在profile路线时,第一个链接有active类,当我在profile.edit路线时,两个链接都有active类.(显然是因为profile.edit访问时两条路线都被激活了.)
如何在子路由中避免父路由链接获取active课程?
基本上我不希望第一个链接(to profile)active在profile.edit路线上有课.
恩惠-v
版本:2.3.0
无法启动守望者; 回退到NodeWatcher以获取文件系统事件.
访问http://www.ember-cli.com/user-guide/#watchman了解更多信息.
节点:5.0.0
os:linux x64
http://www.ember-cli.com/user-guide/#watchman只有mac的解决方案不适用于ubuntu
ember-cli ×10
ember.js ×9
javascript ×2
cors ×1
ember-data ×1
heroku ×1
promise ×1
ubuntu ×1
watchman ×1