[英]Cascading Dropdowns using AngularJS
A merchant has multiple branches. 一个商人有多个分支机构。 When selecting a merchant
I'm trying to make another dropdown list the data from merchant.branches
. 当选择merchant
我尝试制作另一个下拉列表,以显示来自merchant.branches
。分支的数据。
Doing the below does not seem to be resolving the problem: 执行以下操作似乎无法解决问题:
<label>Merchant:</label>
<select ng-if="merchants" ng-model="merchant" ng-options="merchant.name for merchant in merchants track by merchant.id"></select>
<span ng-if="!merchants">Listing merchants, please wait...</span>
<br />
<label>Branch:</label>
<select ng-if="merchant.branches" ng-model="device.branch" ng-options="branch.name for branch in merchant.branches track by branch.id"></select>
<span ng-if="!merchant.branches">Listing branches, please wait...</span>
<pre>
{{ merchant.branches }}
</pre>
Please note that the data is correct and Merchants return properly with their respective branches. 请注意,数据正确无误,商户分别返回各自的分支机构。
Using a different method (By calling ng-change on the first dropdown and then populating the second dropdown). 使用其他方法(通过在第一个下拉列表中调用ng-change,然后填充第二个下拉列表)。 However, is it possible to achieve this without writing any controller code? 但是,是否可以在不编写任何控制器代码的情况下实现这一目标?
I have to guess at how your controller works, but you might have luck with this: 我不得不猜测您的控制器是如何工作的,但是您可能对此感到幸运:
<label>Branch:</label>
<select ng-if="merchant.branches"
ng-model="device.branch"
ng-options="branch.name for branch in merchants[merchant.id].branches track by branch.id"></select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.