3
A
回答
9
我做了一个简单的实现,使用Ember.Select
。
给在jsfiddle
模板一看:
<script type="text/x-handlebars" data-template-name="application">
<h1>Select country and cities</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
{{view "select"
content=countries
optionLabelPath="content.name"
selection=selectedCountry
prompt="Select a country ..."}}
{{view "select"
content=currentCities
prompt="Select a city ..."}}
</script>
控制器:
App = Ember.Application.create({});
App.IndexController = Ember.ObjectController.extend({
selectedCountry: null,
currentCities: null,
countries: [
{
name: 'United States',
cities: ['Chicago', 'Miami']
},
{
name: 'Brazil',
cities: ['Sao Paulo', 'Rio de Janeiro']
}
],
selectedCountryChanged: function() {
this.set('currentCities', this.get('selectedCountry.cities'));
}.observes('selectedCountry')
});
2
在你的控制器,你可以做这样的事情:
indications1a: Ember.A(),
indications1b: Ember.A(),
loadIndications: function (name, parentId) {
var self = this;
$.connection.ccprIndicationsToRevalidation.server.getAllByParentId(parentId)
.done(function (result) {
self.set("indications%@".fmt(name), result);
self.checkIfChildInChildren(name);
});
},
loadChildIndications: function (name1, name2) {
var parent = this.get('content.indication%@'.fmt(name1)),
parents = this.get('indications%@'.fmt(name1)),
childs = this.get('indications%@'.fmt(name2));
childs.clear();
if (!Em.isEmpty(parent) && !Ember.isEmpty(parents)) {
var indication = null;
parents.every(function (item) {
if (Em.isEqual(Ember.get(item, 'id'), parent)) {
indication = item;
return false;
}
return true;
});
if (!Ember.isEmpty(Ember.get(indication, 'hasChildren'))) {
this.loadIndications(name2, indication.id);
} else {
this.set('content.indication%@'.fmt(name2), 0);
}
}
},
checkIfChildInChildren: function (name) {
var child = this.get('content.indication%@'.fmt(name)),
childs = this.get('indications%@'.fmt(name));
var found = false;
childs.every(function (item) {
if (Em.isEqual(Em.get(item, 'id'), child)) {
found = true;
return false;
}
return true;
});
if (!found) {
this.set('content.indication%@'.fmt(name), 0);
}
},
indicationToRevalidation1aChanged: function() {
this.loadChildIndications('1a', '1b');
}.observes('content.indication1a', 'indications1a.length'),
hasNoIndications1b: function() {
return this.get('indications1b.length') === 0;
}.property('indications1b.length'),
在路线的setupController
controller.get('indications1a').clear();
controller.get('indications1b').clear();
controller.loadIndications('1a', null);
车把:
{{view Bootstrap.Forms.Select
label=false
contentBinding="controller.indications1a"
optionLabelPath="content.description"
optionValuePath="content.id"
valueBinding="controller.content.indication1a"}}
{{view Bootstrap.Forms.Select
label=false
contentBinding="controller.indications1b"
optionLabelPath="content.description"
optionValuePath="content.id"
disabledBinding="controller.hasNoIndications1b"
valueBinding="controller.content.indication1b"}}
+0
感谢。我会尽力适应我的需求。 – dangonfast
相关问题
- 1. 根据另一个下拉列表中的选择填充下拉列表
- 2. 根据另一个下拉列表中的选择填充下拉列表
- 3. Mysql根据另一个下拉选项填充下拉列表
- 4. 根据其他其他选择下拉列表填充选择下拉菜单
- 5. 基于GXT中另一个下拉列表的选择填充下拉菜单
- 6. 根据另一个选择填充一个下拉菜单然后重定向
- 7. 根据其他下拉列表的选择填充一个下拉列表
- 8. 根据其他下拉列表的选择填充一个下拉列表
- 9. 根据下拉选择从数据库填充另一个选择下拉菜单
- 10. 根据在PHP中选择的第一个下拉列表填充第二个下拉菜单
- 11. 根据另外2个下拉列表的选择更改下拉菜单?
- 12. 动态填充从另一个下拉列表中选择下拉列表
- 13. Yii填充另一个下拉列表中的下拉列表
- 14. (Angular 2)如何根据另一个下拉选项填充下拉列表
- 15. 从上一个下拉菜单中选择动态填充下拉菜单
- 16. 如何根据上一个下拉选择填充下拉列表SQL
- 17. 根据选定的项目填充选择下拉菜单
- 18. 根据下拉选项填充列表
- 19. 根据另一个下拉列表填充下拉列表在边jQuery
- 20. 如何根据asp.net中另一个下拉列表的选择项填充下拉列表
- 21. 如何根据在另一个下拉列表中选择的值填充下拉列表?
- 22. Laravel 5.4 - 基于另一个下拉选择值填充下拉菜单
- 23. Django - 根据另一个下拉菜单限制下拉选项
- 24. 根据以前的下拉列表选择填充下拉列表
- 25. 从ASP.Net Web窗体中的另一个下拉选择填充下拉列表
- 26. 如何根据另一个下拉列表中的选项动态地填充下拉列表中的选项?
- 27. 根据另一个选择下拉菜单筛选一个HTML选择下拉菜单
- 28. Sharepoint 2007:根据下拉列表框1选择填充下拉列表框2
- 29. MVC下拉列表填充另一个下拉列表
- 30. 从另一个下拉列表填充下拉列表
谢谢!我会试一试! – dangonfast
@Marcio Junior如果我需要在不同的地方使用它,该怎么办? – tvshajeer
如果您必须从所选国家的服务器获取数据,该怎么办 – user2601010