我知道Ember.Application现在有deferReadiness,它允许我在初始化应用程序之前等待AJAX调用的返回.但是,在api文档的示例中,他们将值放入App中的全局变量:
App = Ember.Application.create();
App.deferReadiness();
jQuery.getJSON("/auth-token", function(token) {
App.token = token;
App.advanceReadiness();
});
Run Code Online (Sandbox Code Playgroud)
我没有为令牌引入全局变量,而是将返回的值放入我的ApplicationController中.但是,我现在似乎无法找到如何获得控制器的句柄,即在jQuery回调中.
EmberJS是否支持国际化应用程序的翻译路线?或者它是否至少可以轻松扩展它以支持i18n路线?有经验的人吗?
例如,路由字符串可以通过某种方式从语言环境文件动态设置吗?使用Ember和Rails路由也不会被指定两次......这样会很酷吗?是这样吗?
我是Ember的新手(目前正在评估js框架)但是我一般认为Rails只需要在Rails中指定非常基本的路由,其余的在Ember中指定?那么重复不会太多?想知道来自Rails的语言环境文件是否可用于查找路由转换.
作为一个更普遍的问题:Ember已经支持I18n了吗?
routing ruby-on-rails internationalization ember.js ember-router
在我的应用程序中,我正在显示消息的时间轴.我们按照时间顺序从最新到最旧的顺序从服务器检索它们.
3 - Howdy
2 - Greetings
1 - Mahalo
Run Code Online (Sandbox Code Playgroud)
我们的用户还可以添加一条新消息,默认情况下会在队列末尾插入这样的消息
3 - Howdy
2 - Greetings
1 - Mahalo
4 - I'm the new message, last as usual
Run Code Online (Sandbox Code Playgroud)
当我提交时,我希望在顶部显示新消息.我之前编写了一个函数来反转项目数组,但这对于数组中已有的项目不起作用.
4 - I'm the new message, first finally
3 - Howdy
2 - Greetings
1 - Mahalo
Run Code Online (Sandbox Code Playgroud)
在这种情况下,最好的方法是什么?理想情况是Ember Data可以预先添加到内容数组而不是追加.还有其他选择可能更好吗?
当我有这样的事情:
class A
{
virtual void rat();
};
class B : public A
{
virtual void rat() { ; } //implemented!
};
int main(int argc, char **argv)
{
A *a = new B;
delete a;
}
Run Code Online (Sandbox Code Playgroud)
我收到链接器错误:
除非我让基础老鼠变成纯粹的虚拟.
但是,当我有这个:
class A
{
public:
void rat();
};
int main(int argc, char **argv)
{
A a;
}
Run Code Online (Sandbox Code Playgroud)
这编译很好,并没有给我一个未定义的引用链接错误,除非我明确尝试在我的main(a.rat();)中调用鼠函数.未实现的基类虚函数的规则是什么,然而,如在第一个失败的代码片段中那样在派生类中实现?
在emberjs PRE2我们可以从像任何地方接入路由器
App.get('router')
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议什么可能是emberjs rc1的类似代码?
谢谢
在整个Ember.js文档中,我们可以找到在几个地方提到的动态段的概念.这是什么意思?
我有一个看起来像这样的链接
index.html#/calendar/year/month
Run Code Online (Sandbox Code Playgroud)
这是我设置路线的方式:
App.Router.map(function() {
this.resource('calendar', {path: 'calendar/:currentYear/:currentMonth'});
});
App.CalendarRoute = Ember.Route.extend({
model: function (params) {
var obj = {
weeks: calendar.getDaysInMonth(params.currentMonth, params.currentYear),
currentMonth: params.currentMonth,
currentYear: params.currentYear
};
return obj;
},
setUpController: function(controller, model) {
controller.set('content', model);
}
});
Run Code Online (Sandbox Code Playgroud)
我可以通过这样做:
var currentMonth = this.get('content.currentMonth');
var nextMonth = parseInt(currentMonth)+1;
var route = '#/calendar/'
var year = this.get('content.currentYear');
window.location.href= route + year + '/' + nextMonth;
Run Code Online (Sandbox Code Playgroud)
但我想改用路由器。
我试过:
var router = this.get('target');
router.transitionTo('#calendar/'+year + '/' + nextMonth);
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
未捕获的错误:断言失败:找不到路由#calendar/2013/5
我也试过:
var router …Run Code Online (Sandbox Code Playgroud) 我确信这是非常基本的,但我无法在 ../model 中使用{{#if_eq}}。我什至尝试使用 ../../model 并且它指向 model._revs_info 的子代。
{{#each model._revs_info}}
{{debug ../model}}
{{#if_eq status compare="available"}}
{{debug ../model}}
<a href="#list/{{model.id}}/{{rev}}">{{rev}}</a>
{{/if_eq}}
{{/each}}
Run Code Online (Sandbox Code Playgroud)
{{#if_eq}}已从https://github.com/danharper/Handlebars-Helpers/blob/master/helpers.js复制
/**
* If Equals
* if_eq this compare=that
*/
Handlebars.registerHelper('if_eq', function(context, options) {
if (context == options.hash.compare)
return options.fn(this);
return options.inverse(this);
});
Run Code Online (Sandbox Code Playgroud)
{{debug}}已从http://thinkvitamin.com/code/handlebars-js-part-3-tips-and-tricks/复制
Handlebars.registerHelper("debug", function(optionalValue) {
console.log("Current Context");
console.log("====================");
console.log(this);
if (optionalValue) {
console.log("Value");
console.log("====================");
console.log(optionalValue);
}
});
Run Code Online (Sandbox Code Playgroud) 我在整个网站上使用Ember,甚至是静态页面.
我有一个设计api设置,使用user.new,user.login和user.edit来创建,登录或编辑现有帐户.
任何用户都可以去
http://hostname/user/edit
Run Code Online (Sandbox Code Playgroud)
看到编辑屏幕.我真的希望只有在用户登录时才能实现此目的.如果不是,那么该路由应该例如重定向到登录页面.
有没有办法做到这一点?
有没有人知道最近是否存在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做一些事情.
ember.js ×8
ember-router ×5
ember-data ×2
c++ ×1
inheritance ×1
javascript ×1
promise ×1
routing ×1
virtual ×1