Angularjs x 可编辑的选择选项未显示
Angularjs xeditable selected option not shown
我在 table 中有 editable 行,但我似乎无法 在我的下拉列表 中显示所选值。过程中的其他一切都正常。
代码位于:http://jsfiddle.net/bzLj3a5q/7/
Html:
...
<span editable-select="ad.ad_type_id" e-name="ad_type_id" e-form="rowform" e-ng-options="id as type for (id,type) in ad_types" onshow="showType(ad)">
{{ ad_types[ad.ad_type_id] }}
</span>
...
控制器:
var app = angular.module("app", ['xeditable']);
app.run(function (editableOptions) {editableOptions.theme = 'bs3'; });
app.controller('Ctrl', function ($scope, $filter, $http) {
$scope.ads = [
{
"id": "abc",
"ad_type_id": 1
},
{
"id": "def",
"ad_type_id": 2
}
];
$scope.ad_types = {
"1": "Type1",
"2": "Type2",
"3": "Type3"
};
$scope.showType = function(ad) {
$scope.ad_type_id = ad.ad_type_id;
$scope.apply;
};
});
想通了。将 ad_types
中键的 string 值与 ads
中的 integer 值进行比较时出现问题。解决方案是强制 ad_types
的键为整数,如下所示:
<span editable-select="ad.ad_type_id" e-name="ad_type_id" e-form="rowform" e-ng-options="toInt(id) as type for (id,type) in ad_types">{{ ad_types[ad.ad_type_id] }}</span>
并在控制器中定义toInt(id)
方法:
// We need this to force the key of the ad_types object to an integer
// (as the API returns integer values for ad_type_id)
$scope.toInt = function(key) {
// 10 is the radix, which is the base
return parseInt(key, 10);
}
将您的对象切换为以下内容可解决问题...
$scope.ad_types = {
1: "Type1",
2: "Type2",
3: "Type3"
};
乘以 1 也是一个简单的解决方法..
e-ng-options="(id * 1) 作为 productSizes 中 (id,type) 的类型"
我在 table 中有 editable 行,但我似乎无法 在我的下拉列表 中显示所选值。过程中的其他一切都正常。
代码位于:http://jsfiddle.net/bzLj3a5q/7/
Html:
...
<span editable-select="ad.ad_type_id" e-name="ad_type_id" e-form="rowform" e-ng-options="id as type for (id,type) in ad_types" onshow="showType(ad)">
{{ ad_types[ad.ad_type_id] }}
</span>
...
控制器:
var app = angular.module("app", ['xeditable']);
app.run(function (editableOptions) {editableOptions.theme = 'bs3'; });
app.controller('Ctrl', function ($scope, $filter, $http) {
$scope.ads = [
{
"id": "abc",
"ad_type_id": 1
},
{
"id": "def",
"ad_type_id": 2
}
];
$scope.ad_types = {
"1": "Type1",
"2": "Type2",
"3": "Type3"
};
$scope.showType = function(ad) {
$scope.ad_type_id = ad.ad_type_id;
$scope.apply;
};
});
想通了。将 ad_types
中键的 string 值与 ads
中的 integer 值进行比较时出现问题。解决方案是强制 ad_types
的键为整数,如下所示:
<span editable-select="ad.ad_type_id" e-name="ad_type_id" e-form="rowform" e-ng-options="toInt(id) as type for (id,type) in ad_types">{{ ad_types[ad.ad_type_id] }}</span>
并在控制器中定义toInt(id)
方法:
// We need this to force the key of the ad_types object to an integer
// (as the API returns integer values for ad_type_id)
$scope.toInt = function(key) {
// 10 is the radix, which is the base
return parseInt(key, 10);
}
将您的对象切换为以下内容可解决问题...
$scope.ad_types = {
1: "Type1",
2: "Type2",
3: "Type3"
};
乘以 1 也是一个简单的解决方法..
e-ng-options="(id * 1) 作为 productSizes 中 (id,type) 的类型"