Ember Handlebars helper options.inverse undefined 不是函数
Ember Handlebars helper options.inverse undefined is not a function
所以我有一个模板,我需要 show/hide 一些基于方法的 return 值的文本。我搜索并注意到应该使用 handlebars helpers 来实现这一点。所以我在控制器中添加了一个 resetPassword
助手。 options.fn(this)
部分有效。 options.inverse(this)
没有。它抛出无处不在的 JS 错误 Uncaught TypeError: undefined is not a function
.....
templates/reset-password.hbs:
<div class = "container">
{{#resetPassword}}
<h4>Password has been reset</h4>
<h5>Your new password is: <b>{{password}}</b></h5>
{{else}}
<h4>Something went wrong! </h4>
<h5>The password has not been reset! Please try again later.</h5>
{{/resetPassword}}
</div>
controllers/reset-password.js:
export default Ember.Controller.extend({
token: null,
init: function ()
{
this._super();
Ember.Handlebars.registerHelper('resetPassword', function (options)
{
var token = this.get('token');
var result = false;
/* Ember.$.ajax({
type: "POST",
url: "/reset_password",
contentType: "text/html",
dataType: "json",
async: false,
beforeSend: function (request)
{
request.setRequestHeader("Authorization", token);
},
success: function (data, textStatus)
{
this.set('password', data.password);
result = true;
},
error: function (data, textStatus)
{
result = false;
}
});*/
if (result)
{
return options.fn(this);
}
return options.inverse(this);
});
}
});
所以因为 JS 和 Ember 很烂,这里有一个解决方法:
{{#if resetPassword}}
<h4>Password has been reset</h4>
<h5>Your new password is: <b>{{password}}</b></h5>
{{else}}
<h4>Something went wrong! </h4>
<h5>The password has not been reset! Please try again later.</h5>
{{/if}}
控制器动作:
resetPassword: function ()
{
var self = this;
var token = this.get('token');
var result = false;
Ember.$.ajax({
type: "POST",
url: "/api/users/reset_password",
contentType: "text/html",
dataType: "json",
async: false,
beforeSend: function (request)
{
request.setRequestHeader("Authorization", token);
},
success: function (data, textStatus)
{
var responseUser = data["users"][0];
self.set('password', responseUser.password);
result = true;
},
error: function (data, textStatus)
{
result = false;
}
});
return result;
}.property()
所以我有一个模板,我需要 show/hide 一些基于方法的 return 值的文本。我搜索并注意到应该使用 handlebars helpers 来实现这一点。所以我在控制器中添加了一个 resetPassword
助手。 options.fn(this)
部分有效。 options.inverse(this)
没有。它抛出无处不在的 JS 错误 Uncaught TypeError: undefined is not a function
.....
templates/reset-password.hbs:
<div class = "container">
{{#resetPassword}}
<h4>Password has been reset</h4>
<h5>Your new password is: <b>{{password}}</b></h5>
{{else}}
<h4>Something went wrong! </h4>
<h5>The password has not been reset! Please try again later.</h5>
{{/resetPassword}}
</div>
controllers/reset-password.js:
export default Ember.Controller.extend({
token: null,
init: function ()
{
this._super();
Ember.Handlebars.registerHelper('resetPassword', function (options)
{
var token = this.get('token');
var result = false;
/* Ember.$.ajax({
type: "POST",
url: "/reset_password",
contentType: "text/html",
dataType: "json",
async: false,
beforeSend: function (request)
{
request.setRequestHeader("Authorization", token);
},
success: function (data, textStatus)
{
this.set('password', data.password);
result = true;
},
error: function (data, textStatus)
{
result = false;
}
});*/
if (result)
{
return options.fn(this);
}
return options.inverse(this);
});
}
});
所以因为 JS 和 Ember 很烂,这里有一个解决方法:
{{#if resetPassword}}
<h4>Password has been reset</h4>
<h5>Your new password is: <b>{{password}}</b></h5>
{{else}}
<h4>Something went wrong! </h4>
<h5>The password has not been reset! Please try again later.</h5>
{{/if}}
控制器动作:
resetPassword: function ()
{
var self = this;
var token = this.get('token');
var result = false;
Ember.$.ajax({
type: "POST",
url: "/api/users/reset_password",
contentType: "text/html",
dataType: "json",
async: false,
beforeSend: function (request)
{
request.setRequestHeader("Authorization", token);
},
success: function (data, textStatus)
{
var responseUser = data["users"][0];
self.set('password', responseUser.password);
result = true;
},
error: function (data, textStatus)
{
result = false;
}
});
return result;
}.property()