Javascript 余烬2选择依赖项
我正在尝试在ember中的两个选择框之间创建依赖关系。 我为旧版本的ember找到了一个解决方案: 但是有了新版本和一个包含json+rest的完整模型,我似乎无法让它正常工作。 当我在复选框中选择一个项目时,它应该过滤第二个项目上的元素。但什么也没发生 谢谢 我的代码:Javascript 余烬2选择依赖项,javascript,select,ember.js,Javascript,Select,Ember.js,我正在尝试在ember中的两个选择框之间创建依赖关系。 我为旧版本的ember找到了一个解决方案: 但是有了新版本和一个包含json+rest的完整模型,我似乎无法让它正常工作。 当我在复选框中选择一个项目时,它应该过滤第二个项目上的元素。但什么也没发生 谢谢 我的代码: App = Ember.Application.create({}); App.IndexRoute = Ember.Route.extend({ setupController : function(contr
App = Ember.Application.create({});
App.IndexRoute = Ember.Route.extend({
setupController : function(controller, model) {
this._super(controller, model);
controller.set('producttypes', this.store.find('producttype'));
}
});
App.ProducttypesController = Ember.Object.create({
content: null
});
App.ProductsubtypesController = Ember.Object.create({
content: null
});
App.ProductsubtypeController = Ember.ArrayController.extend({
active: function() {
alert(""); }.property("App.selectedProductType.content").cacheable()
});
//model
App.Producttype = DS.Model.extend({
name: DS.attr(),
});
App.Productsubtype = DS.Model.extend({
name: DS.attr(),
});
var producttypes = {
"producttypes":[
{"id":1,"name":"type1"},
{"id":2,"name":"type2"},
{"id":3,"name":"type3"}
]
};
var productsubtypes = {
"productsubtypes":[
{"id":4,"name":"type4","type_id":"1"},
{"id":5,"name":"type5","type_id":"1"},
{"id":6,"name":"type6","type_id":"3"}
]
};
$.mockjax({
url: '/producttypes',
dataType: 'json',
type: 'get',
responseText: producttypes
});
$.mockjax({
url: '/productsubtypes',
dataType: 'json',
type: 'get',
responseText: productsubtypes
});
我找到了解决我问题的办法 控制员:
App.IndexController = Ember.Controller.extend({
selectedProductTypeChanged: function(){
var obj = this.get('selectedProductType');
if (obj != null) {
console.log(typeof obj.id);
var unfiltered=this.get('productsubtypes');
var filtered=this.get('productsubtypes').filterProperty("producttype",obj.id);
this.set('filterproductsubtypes',filtered );
this.set('selectedProductSubType',null);
}
}.observes('selectedProductType')
});
链接到jsbin:你是说依赖关系吗?另外,请在您的问题中直接包含相关的代码片段