简而言之,我正在尝试重现jquery-ui的购物车演示的基本版本:http://jqueryui.com/demos/droppable/shopping-cart.html with ember.js和HTML5 native drag n drop.
之前尝试使用ember + jquery-ui实现拖放并且难以使用此解决方案:http://jsfiddle.net/Wu2cu/2/,我看到了pangratz的HTML5解决方案:http://jsfiddle.net/pangratz666/ DYnNH /并决定试一试.
我已经分叉了pangratz的jsfiddle,创建了一个productsController和一个添加的ToTartController,它根据isAdded属性过滤了productsController:http://jsfiddle.net/GU8N7/3/
这很好,但是当我尝试使用#each迭代器并将唯一的可拖动视图附加到迭代器中的每个对象时,我就会陷入困境.我希望能够拖动每个"产品"对象,当它被放入"购物车"区域时,将该对象的isAdded属性设置为true,从而将其显示在"购物车"中.
任何帮助将不胜感激!!
(也作为奖励,我想让购物车中的物品可以分类,但在第一座桥越过之前,这可能要求太多了.)
我对一个看似简单的余烬问题感到困惑.我正在使用active_model_serializers元数据序列化从rails控制器序列化我的rails current_user方法,然后使用这个人的临时解决方案提取并将current_user meta json设置为全局ember变量.
App.CustomRESTSerializer = DS.RESTSerializer.extend({
extractMeta: function(loader, type, json) {
var meta;
meta = json[this.configOption(type, 'meta')];
if (!meta) { return; }
Ember.set('App.metaData', meta);
this._super(loader, type, json);
}
});
Run Code Online (Sandbox Code Playgroud)
一切都很好,直到这一点.现在,我可以通过键入App.metaData.current_user以及通过调用特定属性从句柄访问控制台中的current_user信息,即:
{{App.metaData.current_user.email}}
Run Code Online (Sandbox Code Playgroud)
并且该电子邮件属性显示在模板中.当我尝试从ember控制器中访问该全局变量时,问题就出现了.这看起来非常简单,但我似乎无法从任何ember控制器中访问current_user.我试过了:
currentUserBinding: 'App.metaData.current_user',
currentUser: function() {
return App.metaData.current_user;
}.property(),
Ember.get('App.metaData.current_user')
Run Code Online (Sandbox Code Playgroud)
和其他一些方法,但似乎无法访问它.奇怪的是,我可以通过直接路径从控制台和把手内轻松访问current_user,但不能从ember控制器中访问.我一定错过了一些明显的东西.
非常感谢任何帮助!
所以如果最初的问题是tl; dr,我想我真正需要知道的是如何转向:
App.CompaniesController = Em.ArrayController.extend({
content: [
App.Company.create({ markerText: "Bondi Bar", lat: -33.890542, lng: 151.274856, number: 4, iconUrl: "http://www.kjftw.com/sandbox/gmap/images/icons/numeric/red04.png", isOpen: true}),
App.Company.create({ markerText: "Coogee Beach Grill", lat: -33.923036, lng: 151.259052, number: 5, iconUrl: "http://www.kjftw.com/sandbox/gmap/images/icons/numeric/red05.png", isOpen: false}),
App.Company.create({ markerText: "Maroubra Smoke Shop", lat: -33.950198, lng: 151.259302, number: 1, iconUrl: "http://www.kjftw.com/sandbox/gmap/images/icons/numeric/red01.png", isOpen: true}),
],
open: function() {
return this.get('content').filterProperty('isOpen', true);
}.property('content.@each')
});
Run Code Online (Sandbox Code Playgroud)
进入一个简单的数组:
var locations = [
['Bondi Bar', -33.890542, 151.274856, 4, 'http://www.kjftw.com/sandbox/gmap/images/icons/numeric/red04.png'],
['Maroubra Smoke Shop', -33.950198, 151.259302, 1, 'http://www.kjftw.com/sandbox/gmap/images/icons/numeric/red01.png']];
Run Code Online (Sandbox Code Playgroud)
或修改:
for …
Run Code Online (Sandbox Code Playgroud)