我有两个选择菜单,通过页面加载后获取的AJAX JSON数据填充。它们通过自己的模型链接,看起来像这样;
<select name="category"
id="category"
ng-model="category"
ng-options="category as category.name for category in categories track by category.name">
<option value=''>Select category</option>
</select>
<select name="product"
id="product"
ng-disabled="!category"
ng-model="product"
ng-options="product for product in category.products">
<option value=''>Select product</option>
</select>
将表单提交给API后,如果使用origin
和category
字符串,则会返回product
个对象。
我认为我应该能够将$scope.category
和/或$scope.product
设置为返回的origin
数据,以便在选择菜单中预先选择项目;
.success(function(data)) {
...
$scope.category = data.origin.category
...
}
但这不起作用......
答案 0 :(得分:1)
您可以使用ng-init
选择初始值
<select ng-init="initDefaultCategory(categories)" name="category" id="category" ng-model="category" ng-options="category as category.name for category in categories track by category.name">
<option value=''>Select category</option>
</select>
<select ng-init="initDefaultProduct(category.products)" name="product" id="product" ng-disabled="!category" ng-model="product" ng-options="product for product in category.products">
<option value=''>Select product</option>
</select>
正在使用 DEMO
<强> EDITS 强>
如果要选择默认值,可以执行以下操作
<强>控制器强>
$scope.initDefaultCategory = function(categories, value) {
if (categories.length > 0)
$scope.category = categories.filter(e => e.name == value)[0];
}
您可以在ng-init
<select ng-init="initDefaultCategory(categories,'All')" name="category" id="category" ng-model="category" ng-options="category as category.name for category in categories track by category.name">
<option value=''>Select category</option>
</select>
答案 1 :(得分:1)
public class MonthAxisValueFormatter implements IAxisValueFormatter {
protected String[] mMonths;
private Context context;
private BarLineChartBase<?> chart;
public MonthAxisValueFormatter(BarLineChartBase<?> chart, Context context) {
this.chart = chart;
this.context = context;
mMonths = new String[]{
this.context.getResources().getString(R.string.january),
this.context.getResources().getString(R.string.february),
this.context.getResources().getString(R.string.march),
this.context.getResources().getString(R.string.april),
this.context.getResources().getString(R.string.may),
this.context.getResources().getString(R.string.june),
this.context.getResources().getString(R.string.july),
this.context.getResources().getString(R.string.august),
this.context.getResources().getString(R.string.september),
this.context.getResources().getString(R.string.october),
this.context.getResources().getString(R.string.november),
this.context.getResources().getString(R.string.december)
};
}
@Override
public String getFormattedValue(float value, AxisBase axis) {
int month = (int) value;
String monthName = mMonths[month % mMonths.length];
return monthName;
}
}