- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前在这门类(class)中遇到的问题是:
We want rating to be part of a review object, so go ahead and add it to our Review object. Also add a rating, set to a number between 1 and 5, on each review fixture.
我已经为每个灯具添加了正确的评级,但我正在努力解决这个问题到底要我调整什么。其他 2 个问题已通过此示例。我的假设是我必须将评级纳入评论属性,但这个级别很痛苦。
如果没有我的常规开发工具,它不会向我显示这是抛出的错误...
有什么建议吗?
我的代码块:
var App = Ember.Application.create({
LOG_TRANSITIONS: true
});
App.Router.map(function() {
this.route('credits', { path: '/thanks' });
this.resource('products', function() {
this.resource('product', { path: '/:product_id' });
this.route('onsale');
this.route('deals');
});
this.resource('contacts', function() {
this.resource('contact', { path: '/:contact_id' });
});
});
App.IndexController = Ember.ArrayController.extend({
productsCount: Ember.computed.alias('length'),
logo: 'images/logo-small.png',
time: function() {
return (new Date()).toDateString();
}.property(),
onSale: function() {
return this.filterBy('isOnSale').slice(0,3);
}.property('@each.isOnSale')
});
App.ContactsIndexController = Ember.Controller.extend({
contactName: 'Anostagia',
avatar: 'images/avatar.png',
open: function() {
return ((new Date()).getDay() === 0) ? "Closed" : "Open";
}.property()
});
App.ProductsController = Ember.ArrayController.extend({
sortProperties: ['title']
});
App.ContactsController = Ember.ArrayController.extend({
sortProperties: ['name'],
contactsCount: Ember.computed.alias('length')
});
App.ReviewsController = Ember.ArrayController.extend({
sortProperties: ['reviewedAt'],
sortAscending: false
});
App.ContactProductsController = Ember.ArrayController.extend({
sortProperties: ['title']
});
App.ProductController = Ember.ObjectController.extend({
ratings: [1,2,3,4,5],
isNotReviewed: Ember.computed.alias('review.isNew'),
review: function(){
return this.store.createRecord('review',{
product: this.get('model'),
rating: this.get('rating')
});
}.property('model'),
actions: {
createReview: function(){
var controller = this;
this.get('review').set('reviewedAt', new Date());
this.get('review').save().then(function(review){
controller.get('model.reviews').addObject(review);
});
}
}
});
App.ProductsRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('product');
}
});
App.ContactsRoute = Ember.Route.extend({
model: function() {
return this.store.findAll('contact');
}
});
App.IndexRoute = Ember.Route.extend({
model: function(){
return this.store.findAll('product');
}
});
App.ProductsIndexRoute = Ember.Route.extend({
model: function(){
return this.store.findAll('product');
}
});
App.ProductsOnsaleRoute = Ember.Route.extend({
model: function(){
return this.modelFor('products').filterBy('isOnSale');
}
});
App.ProductsDealsRoute = Ember.Route.extend({
model: function(){
return this.modelFor('products').filter(function(product){
return product.get('price') < 500;
});
}
});
App.ProductDetailsComponent = Ember.Component.extend({
reviewsCount: Ember.computed.alias('product.reviews.length'),
hasReviews: function(){
return this.get('reviewsCount') > 0;
}.property('reviewsCount')
});
App.ContactDetailsComponent = Ember.Component.extend({
productsCount: Ember.computed.alias('contact.products.length'),
isProductive: function() {
return this.get('productsCount') > 3;
}.property('productsCount')
});
App.ProductView = Ember.View.extend({
isOnSale: Ember.computed.alias('controller.isOnSale'),
classNameBindings: ['isOnSale']
});
App.ApplicationAdapter = DS.FixtureAdapter.extend();
App.Product = DS.Model.extend({
title: DS.attr('string'),
price: DS.attr('number'),
description: DS.attr('string'),
isOnSale: DS.attr('boolean'),
image: DS.attr('string'),
reviews: DS.hasMany('review', { async: true }),
crafter: DS.belongsTo('contact', { async: true }),
rating: function() {
if(this.get('reviews.length') === 0) { return 0; }
return this.get('reviews').reduce(function(previousValue, review) {
return previousValue + review.get('rating');
}, 0) / this.get('reviews.length');
}.property('reviews.@each.rating')
});
App.Product.FIXTURES = [
{ id: 1,
title: 'Flint',
price: 99,
description: 'Flint is a hard, sedimentary cryptocrystalline form of the mineral quartz, categorized as a variety of chert.',
isOnSale: true,
image: 'images/products/flint.png',
reviews: [100,101],
crafter: 200
},
{
id: 2,
title: 'Kindling',
price: 249,
description: 'Easily combustible small sticks or twigs used for starting a fire.',
isOnSale: false,
image: 'images/products/kindling.png',
reviews: [],
crafter: 201
},
{
id: 3,
title: 'Matches',
price: 499,
description: 'One end is coated with a material that can be ignited by frictional heat generated by striking the match against a suitable surface.',
isOnSale: true,
reviews: [],
image: 'images/products/matches.png',
crafter: 201
},
{
id: 4,
title: 'Bow Drill',
price: 999,
description: 'The bow drill is an ancient tool. While it was usually used to make fire, it was also used for primitive woodworking and dentistry.',
isOnSale: false,
reviews: [],
image: 'images/products/bow-drill.png',
crafter: 200
},
{
id: 5,
title: 'Tinder',
price: 499,
description: 'Tinder is easily combustible material used to ignite fires by rudimentary methods.',
isOnSale: true,
reviews: [],
image: 'images/products/tinder.png',
crafter: 201
},
{
id: 6,
title: 'Birch Bark Shaving',
price: 999,
description: 'Fresh and easily combustable',
isOnSale: true,
reviews: [],
image: 'images/products/birch.png',
crafter: 201
}
];
App.Contact = DS.Model.extend({
name: DS.attr('string'),
about: DS.attr('string'),
avatar: DS.attr('string'),
products: DS.hasMany('product', { async: true })
});
App.Contact.FIXTURES = [
{
id: 200,
name: 'Giamia',
about: 'Although Giamia came from a humble spark of lightning, he quickly grew to be a great craftsman, providing all the warming instruments needed by those close to him.',
avatar: 'images/contacts/giamia.png',
products: [1,4]
},
{
id: 201,
name: 'Anostagia',
about: 'Knowing there was a need for it, Anostagia drew on her experience and spearheaded the Flint & Flame storefront. In addition to coding the site, she also creates a few products available in the store.',
avatar: 'images/contacts/anostagia.png',
products: [2,3,5,6]
}
];
App.Review = DS.Model.extend({
text: DS.attr('string'),
reviewedAt: DS.attr('date'),
product: DS.belongsTo('product')
});
App.Review.FIXTURES = [
{
id: 100,
rating: 2,
text: "Started a fire in no time!"
},
{
id: 101,
rating: 4,
text: "Not the brightest flame, but warm!"
}
];
我最好的猜测与这个函数有关......
review: function(){
return this.store.createRecord('review',{
product: this.get('model'),
rating: this.get('rating')
});
}.property('model'),
最佳答案
在进一步审查和董事会的一些帮助之后,就像将它添加到模型一样简单:
App.Review = DS.Model.extend({
text: DS.attr('string'),
reviewedAt: DS.attr('date'),
product: DS.belongsTo('product'),
rating: DS.attr('number')
});
关于javascript - codeschool emberjs 7.7 不接受评分对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24111143/
随着从 SproutCore 2.0 到 EmberJS 的迁移,有命名空间和 Github 存储库迁移。核心的东西好像移到了http://github.com/emberjs组织 Github 帐户
我有一条使用 ArrayController 来显示对象的路线。在执行某些操作后,使用 controller.clear() 和 controller.addObjects() 方法再次填充数组。我需
我有一个在 Ember 中创建的自定义 View 。我真的很喜欢 {{yield}} helper 让我控制三明治的“面包”。但是,我现在想要做的是创建一个“双层”三明治,并有一个超过 1 个产量的
过去 6 个月我正在开发一个 Emberjs 组件。 当我尝试开发表格组件时,我开始遇到第一个性能问题。此表中的每个单元格都是 Ember.View,并且每个单元格都绑定(bind)到对象属性。当表格
我有一个名为 docTemplateID 的变量/操作。docTemplateID 的值可以是 1 或 2单击按钮 1 设置 docTemplateID = 1。单击“提交”按钮将使用新值创建 doc
我正在尝试编写一个小 Action 来搜索数据存储,顺便说一下,数据存储中已经加载了数据。我希望能够通过字符串(即名字)进行搜索。 这是我到目前为止的代码示例。 this.get() 正在从搜索表单中
我正在尝试在注册表单上创建提交操作。这是我的寄存器 handle : {{input class="form-control" value=username type="text" pl
我有一个我认为相当正常的 JSON 响应: "data": { ..... "user": { "name": "John", "surname": "Doe" } .
如何定义仅在按下特定修饰键时调用的操作(单击时)? allowedKeys当没有按下修饰键时也会执行该操作。 最佳答案 一种方法就是做 my item 在你的 Controller /父组件中
所以,这基本上就是我想要的。但我需要获取可以在 ember 检查器中看到的当前路径,但如何在组件中获取它?或者有更好的方法来做到这一点吗?也许是一项服务? import Ember from 'emb
我只是想循环遍历我生成的一些虚拟数据,这样我就可以设置网站的样式,我的路由器中有这个: import Ember from 'ember'; export default Ember.Route.ex
这就是我所拥有的。 2 种模型:“注释”和“用户”。注释有一个名为“用户”的字段,它使“1 个用户对应多个注释”进行复制。数据取自 Mirage。 备注型号: export default DS.Mo
我尝试复制搜索字段,就像它们在 emberjs.com 处显示的那样。但是由于某种原因,当输入查询并按 Enter 或单击提交按钮时,我的代码不断产生以下错误(在 google chrome 中):
我正在测试过滤器内容,仅显示 X 个结果,我必须使用计数器来执行此操作,因为适配器如何返回数据。 http://jsfiddle.net/eAvET/ 当您加载此修改后的示例时,显示 0 数据,但是当
我的应用程序有一个名为 Balance 的模型,我们可以在其中添加金额和说明。我创建了一个操作,当您单击按钮时添加一些余额记录,到目前为止效果很好。问题是我创建了一个名为“totalBalance”的
我正在使用 ember 的查询参数按布局类型过滤结果列表。我想检查指定的查询是否在 availableLayouts 中。我知道我可以检查该值是否在此数组中,但我不确定 ember 在什么时候设置“布
我有一段数据(对象),它从服务器端脚本打印为全局变量。 user = { id : 1, name: 'foo', avatar : 'http://foo.com/avatar.jpg'} 整个应用
我正在使用 Ember 构建一个单页音乐网络应用程序。每个轨道在页面上都表示为一个组件。给定页面上有许多轨道。当用户单击播放时,组件会更新其 UI 以反射(reflect)这一点,并且主路由会跟踪当前
我想将社交分享按钮(fb、twitter、vk)添加到我的 Ember 应用程序中。我找到了一些库并集成了它们,但它们有一个重要的限制。社交网络使用其机器人抓取共享页面,并从页面中检索特定的元属性。但
我试图用easyForm预选一个选择框。 https://github.com/dockyard/ember-easyForm 我做了一个JsBin:http://emberjs.jsbin.com/
我是一名优秀的程序员,十分优秀!