这里的两个函数都返回'undefined‘。我不知道问题出在哪里。看起来很直白??
在控制器中,我设置了一些属性来向用户显示一个空的文本字段,以确保他们输入自己的数据。
Amber.ProductController = Ember.ObjectController.extend ({
quantity_property: "",
location_property: "",
employee_name_property: "",
//quantitySubtract: function() {
//return this.get('quantity') -= this.get('quantity_property');
//}.property('quantity', 'quantity_property')
quantitySubtract: Ember.computed('quantity', 'quantity_property', function() {
return this.get('quantity') - this.get('quantity_property');
});
});在路线中,正在设置employeeName和位置...
Amber.ProductsUpdateRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('product', params.product_id);
},
//This defines the actions that we want to expose to the template
actions: {
update: function() {
var product = this.get('currentModel');
var self = this; //ensures access to the transitionTo method inside the success (Promises) function
/* The first parameter to 'then' is the success handler where it transitions
to the list of products, and the second parameter is our failure handler:
A function that does nothing. */
product.set('employeeName', this.get('controller.employee_name_property'))
product.set('location', this.get('controller.location_property'))
product.set('quantity', this.get('controller.quantitySubtract()'))
product.save().then(
function() { self.transitionTo('products') },
function() { }
);
}
}
});车把上没有什么特别的东西
<h1>Produkt Forbrug</h1>
<form {{action "update" on="submit"}}>
...
<div>
<label>
Antal<br>
{{input type="text" value=quantity_property}}
</label>
{{#each error in errors.quantity}}
<p class="error">{{error.message}}</p>
{{/each}}
</div>
<button type="update">Save</button>
</form>发布于 2014-10-28 23:58:54
去掉()
product.set('quantity', this.get('controller.quantitySubtract'))这种方式很好:
quantitySubtract: function() {
return this.get('quantity') - this.get('quantity_property');
}.property('quantity', 'quantity_property')更新:
看到您的路由,该控制器将不会应用于该路由,它只是使用一个通用Ember.ObjectController。
Amber.ProductController会去Amber.ProductRoute
Amber.ProductUpdateController会去Amber.ProductUpdateRoute
如果您想在两个路径上重用控制器,只需像这样扩展产品控制器即可。
Amber.ProductController = Ember.ObjectController.extend ({
quantity_property: "",
location_property: "",
employee_name_property: "",
quantitySubtract: function() {
return this.get('quantity') - this.get('quantity_property');
}.property('quantity', 'quantity_property')
});
Amber.ProductUpdateController = Amber.ProductController.extend();发布于 2014-10-29 02:04:25
我最终跳过了这个函数,而是这样做:
product.set('quantity',
this.get('controller.quantity') - this.get('controller.quantity_property'))我还是不明白为什么我不能使用那个函数..我还试着重命名控制器..但这不是问题所在..如前所述,要提取到控制器的另外两个值...
无论如何,谢谢你试着帮助我!
https://stackoverflow.com/questions/26612559
复制相似问题