[英]Send array - Cannot read property 'map' of undefined
我將如何發送多個值以繼續像客戶可以創建用戶一樣。
我在這里找到它: https : //stackoverflow.com/a/14520103/7180653 ( 使用對象數組作為輸入數據 )
我基於他的代碼,這就是我應該只擁有真實知識的價值的方式。
當我看着我的按鈕時。 所以我得到這個錯誤 :
數組[0]
TypeError:無法讀取未定義的屬性“ map”
html-視圖:
<ul style="list-style-type:none;">
<li class="col-md-4" ng-repeat="Value in ColorAddUppers">
<img ng-src="{{Value.Image}}" class="img-responsive img-rounded mb-lg" />
<p class="label label-lg label-primary full-width">
<input type="checkbox"
ng-model="Value.selected"
name="selectedColorUppers[]"
value="{{Value.IDColor}}" />
{{Value.Text}}
</p>
</li>
</ul>
CreateUser.js
var url = "/JsonClass/ColorAddToUppers";
$http.get(url).success(function (response) {
$scope.ColorAddUppers = response;
});
//Overdel
$scope.NextLvlThree = function () {
//Check Color Values
$scope.selectionColorUppersView = [];
$scope.selectedColorUppers = function selectedColorUppers() {
return filterFilter($scope.ColorAddUppers, { selected: true });
};
$scope.$watch('fruits|filter:{selected:true}', function (nv) {
$scope.selectionColorUppersView = nv.map(function (ColorNameUppersText) {
return ColorNameUppersText.Text;
});
}, true);
console.log($scope.selectionColorUppersView);
}
EIDT(更新)
當我看這張照片時,好像沒有得到我的價值觀。
我在代碼中使用了這個:
$scope.selectedTextValuesByWatch = [];
$scope.$watchCollection('ColorAddUppers|filter:{selected:true}', function (nv, ov) {
$scope.selectedTextValuesByWatch = nv.filter(function (value) {
return value.selected;
}).map(function (value) {
return value.Text;
});
}, true);
$scope.getSelectedTextValues = function () {
return $scope.ColorAddUppers.filter(function (value) {
return value.selected;
}).map(function (value) {
return value.Text;
});
}
console.log($scope.selectedTextValuesByWatch);
if($scope.selectedTextValuesByWatch.length >= 1)
{
console.log("check");
}
else
{
console.log("error");
}
我不確定何時調用NextLvlThree()
函數,但是$watch
的聲明應該在控制器級別,而不是在此函數內部,以免出現多個聲明。
無論如何,有幾種方法可以獲取列表中的選定值:
在視圖中使用動態過濾器,例如應將選擇值顯示為json:
<pre>{ColorAddUppers|filter:{selected:true}|json}}</pre>
使用手表將更新僅包含每個值的Text
的所選列表:
$scope.$watchCollection('ColorAddUppers|filter:{selected:true}', function (nv, ov) {
$scope.selectedTextValuesByWatch = nv.filter(function (value) {
return value.selected;
}).map(function(value) {
return value.Text;
});
}, true);
或者只是使用一個功能與手表相同的功能,但是當用戶單擊某個按鈕時:
$scope.getSelectedTextValues = function() {
return $scope.ColorAddUppers.filter(function(value) {
return value.selected;
}).map(function(value) {
return value.Text;
});
}
在這里查看這輛unk車中的所有3 輛 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.