我尝试了一个简单的应用程序,但我很困惑,因为什么时候在控制器中使用模型钩子,什么时候去路由模型钩子.以此为例(使用EmberCLI):
模板(templates/discovery.hbs)
{{#each model}}
<tr>
<td>
Q: {{ques}}
</td>
</tr>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
所以我可以用以下两种方式定义模型
**第一路(路线/ discovery.js)**
import Ember from "ember";
export default Ember.Route.extend({
model : function(){
return this.store.all('questions') ;
}
});
Run Code Online (Sandbox Code Playgroud)
这与预期一样,所有类型问题的记录都传递并在discovery.hbs模板中显示.
第二种方式(controllers/discovery.js)
import Ember from "ember";
export default Ember.ArrayController.extend({
model : function(){
return this.store.all('questions') ;
}
});
Run Code Online (Sandbox Code Playgroud)
所以预计这将像以前一样(至少我预期它),但这并没有显示任何记录.那么如果我在路线或控制器中定义模型有什么区别?什么应该是首选?
我正在尝试在Ember CLI应用程序中更改roolURL.在基本的Ember应用程序中这很容易:
App.Router.reopen({
rootURL: '/blog/'
});
Run Code Online (Sandbox Code Playgroud)
在Ember CLI应用程序中执行此操作会引发以下异常:
Uncaught TypeError: Cannot read property 'reopen' of undefined
Run Code Online (Sandbox Code Playgroud)
我之所以这样做,是因为我将在rails应用程序中安装多个Ember CLI应用程序.URL将如下所示:
/ --> rails
/foo --> rails
/api --> rails
/admin --> Ember CLI
/blog --> Ember CLI
Run Code Online (Sandbox Code Playgroud) 我试图在Apache tomcat上加载我的ember-cli内置服务器应用程序.
我使用生成模式构建我的应用程序
余烬建设 - 环境生产
我将我的/ dist文件夹中的文件移动到我的apache tomcat / webapps文件夹启动了我的apache服务器但是当我转到URL时:"localhost:8081/index.html"
页面是空白的,尽管它与内置服务器完美配合.使用Ember检查器,我可以看到已定义但无法查看任何输出的路径.
我按照本指南http://thetechcofounder.com/getting-started-with-ember-js-using-ember-cli/# = 来创建我的ember-cli应用程序,任何帮助都会很棒.
我正在将基于全局变量的实时Ember应用程序转换为使用ember-cli的基于es6的应用程序.在我的应用程序中,我需要经常了解当前的路线.在全局版本中,我正在这样做.
全球模式
var MyApp = Ember.Application.create({
currentRoute : ''
});
MyApp.Route = Ember.Route.extend({
actions : {
didTransition : function () {
MyApp.set('currentRoute', this);
}
}
});
Run Code Online (Sandbox Code Playgroud)
然后,我可以MyApp.get('currentRoute')在我的会话或离线控制器中确定在发生某些事件时如何/在何处转换.
使用ember-cli时,我导入应用程序以便能够从必要的控制器中引用它.
import MyApp from "../app";
Run Code Online (Sandbox Code Playgroud)
但事实证明MyApp.currentRoute,MyApp.get和MyApp.set都是不确定的.
我的一部分认为这是ember-cli中的一个错误,即应用程序实例不再绑定getter和setter.我的一部分意识到将应用程序实例存储在一起并不是一个很好的做法.
我可以解决这个问题,通过转换的所有实例MyApp.get,并MyApp.set以Ember.get(MyApp, ...)和Ember.set(MyApp, ...)分别,但我想我会先问这里,因为这似乎要么是与Ember,CLI或其他什么东西的问题,其中有达到什么更好的推荐方式我需要.
我有两个组成部分:SpecialButtonComponent和SpecialButtonDerivativeComponent.
该SpecialButton组件自动使用在的模板/app/templates/components/special-button.hbs.
我想SpecialButtonDerivativeComponent使用相同的模板,但到目前为止,我没有运气尝试使用这种技术:
// app/components/special-button-derivative.js
import SpecialButtonComponent from './special-button';
export default SpecialButtonComponent.extend({
templateName: 'components/special-button'
});
Run Code Online (Sandbox Code Playgroud)
我也尝试使用layoutName而不是templateName,但仍然没有运气.有任何想法吗?
在使用ember CLI时,我得到了这个:
version: 0.1.5
Could not find watchman, falling back to NodeWatcher for file system events
我真的不在乎它是否使用了守望者或NodeWatcher ...... - 但我不喜欢这个消息 - 我想用ember想要的东西.我用自制软件安装了守望者......但仍然是这个消息.有任何想法吗?
我是带守望者的3.0.0版本 - 和带有余烬的0.1.5版本.
当我 watchman watch ~/sites/mySite
我明白了
dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib
Referenced from: /usr/local/bin/watchman
Reason: image not found
Trace/BPT trap: 5
这是醇 - "酿造物品在非常规点"的问题吗?
这是我使用的余烬库:
ember-cli : 0.1.7
Ember : 1.8.1
Ember Data : 1.0.0-beta.12
Handlebars : 1.3.0
Run Code Online (Sandbox Code Playgroud)
我的config / environment.js文件包含一些api密钥。根据链接(http://www.ember-cli.com/#Environments),我可以使用路径../config/environment或your-application-name / config / environment从环境文件访问变量。
现在,我需要控制器中环境文件中的URL,并且我有以下代码:
import Ember from "ember";
import BaseController from 'appkit/controllers/base-controller';
import config from '../config/environment';
var NavigationController = BaseController.extend({
homeUrl: config.URL
});
export default NavigationController;
Run Code Online (Sandbox Code Playgroud)
检查浏览器时,出现以下错误:
Error: Could not find module appkit/controllers/config/environment
Run Code Online (Sandbox Code Playgroud)
我使用“ appkit / config / environment”(根据上述链接)更改了从控制器的导入路径,并得到了相同的错误消息。问题在于config / environment.js文件不在appkit / controllers文件夹中,但与appkit文件夹位于同一级别。
我的问题是从控制器导入配置/环境的路径是什么。请指教!
谢谢
我想将工具提示添加到组件中的按钮上,该按钮可以根据服务器返回的一组结果显示.(即用于删除,编辑等的操作按钮)
我创建了一个"搜索"组件,该组件呈现在应用程序中,当单击搜索按钮时,服务器可能会将多个行返回到同一个搜索组件模板中.
例如:
我的应用程序内/荚/实际数据/ template.hbs
包含:
…
{{#if results}}
<div class="row">
<div class="col-sm-3"><b>Factual ID</b></div>
<div class="col-sm-2"><b>Name</b></div>
<div class="col-sm-2"><b>Town</b></div>
<div class="col-sm-2"><b>Post Code</b></div>
<div class="col-sm-2"><b>Actions</b></div>
</div>
{{/if}}
{{#each result in results}}
<div class="row">
<div class="col-sm-3">{{result.factual_id}}</div>
<div class="col-sm-2">{{result.name}}</div>
<div class="col-sm-2">{{result.locality}}</div>
<div class="col-sm-2">{{result.postcode}}</div>
<div class="col-sm-2">
<button {{action "clearFromFactual" result.factual_id}} class="btn btn-danger btn-cons tip" type="button" data-toggle="tooltip" class="btn btn-white tip" type="button" data-original-title="Empty this Row<br> on Factual" ><i class="fa fa-check"></i></button>
</div>
</div>
{{/each}}
…
Run Code Online (Sandbox Code Playgroud)
但是由于元素插入检测/计时问题,我无法获得工具提示代码的功能.在组件中
我的app/pods/factual-data/component.js包含:
...
didInsertElement : function(){
console.log("COMPONENT: didInsertElement");
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent); …Run Code Online (Sandbox Code Playgroud) 我一直在尝试部署到Heroku它,它一直在给我一个错误.显然node 0.12是不兼容node-sass所以我更新到node-sass 2.0.1但它仍然无法正常工作.我正在使用ember cli 0.1.15
Module did not self-register.
Error: Module did not self-register.
at Error (native)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/tmp/build_9fa8a1b16bb172aacd5dffe37fe967c1/node_modules/broccoli-sass/node_modules/node-sass/lib/index.js:181:15)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
! Push rejected, failed to compile Ember CLI app
Run Code Online (Sandbox Code Playgroud) 我是初学者并且做了一个介绍性的教程来构建一个简单的应用程序.当我创建一个新应用程序并启动服务器时,我尝试在浏览器中访问localhost页面(http:// localhost:4200 /),但该页面为空白.浏览器窗口标题是我的应用程序名称,但它们应该没有"欢迎使用Ember"文本.此外,余烬检查员说"未检测到Ember应用程序!" 虽然小的余烬图标出现在Firefox的地址栏中,表明有一个余烬应用程序.
我已经尝试重新启动教程 3次,并得出相同的结果.我已按照此处提供的所有设置步骤进行操作.我唯一不同的事情或者除了turorial之外我还是sudo chown -R $USER /usr/local因为权限问题而不得不运行.
到目前为止,我所做的只是安装节点,npm,bower,ember-cli 2.2.0-beta.2.,然后运行以下几个命令:
ember new ember2-blog
cd ember2-blog
ember server
Run Code Online (Sandbox Code Playgroud)
终端给了我一个"建立成功 - 7016ms".消息,但我去http:// localhost:4200 /并看到空白页...检查员说"没有检测到任何ember应用程序".似乎我错过了一些简单的东西,但无法弄明白.这与权限有关吗?拜托,谢谢你的帮助.
ember-cli ×10
ember.js ×10
ember-data ×2
ecmascript-6 ×1
heroku ×1
node.js ×1
routing ×1
tomcat ×1
watchman ×1