从json获取最大插槽并应用于控制器
I have a upload form where once you upload and preview the image you can add it to a list depending that the list has less than the max slots filled.
我有一个上传表单,一旦您上传和预览图像,您可以将其添加到列表中,具体取决于列表的填充小于最大插槽数。
for example:
例如:
If max slots is 5 then you can add 5 images, if more then the program will tell you to remove a image as you have hit the max slots.
如果最大插槽为5,那么您可以添加5个图像,如果更多,则程序会告诉您在达到最大插槽时删除图像。
my json looks as following
我的json看起来如下
Error I'm Getting
我得到的错误
I am not getting to upload and keep getting
我无法上传并继续上传
TypeError: Cannot read property 'max_slots' of undefined
even though the path in my json to max slots is campaigns[index].max_slots as you can see in the image above.
即使我的json到最大插槽的路径是广告系列[index] .max_slots,如上图所示。
Im not sure whats going wrong can someone help out please ?
我不确定有什么问题会有人帮帮忙吗?
JavaScript
JavaScript的
.controller('Dashboard', function ($scope, $http, $timeout) {
$scope.campaigns = [];
$scope.preview = '';
$scope.addImage = function (index) {
if ($scope.length < $scope.campaigns[index].max_slots) {
$scope.slots.push({
"slot_id": $scope.length + 1,
"base_image": $scope.preview,
"path_image": ""
});
} else {
window.alert("you have to delete a slot to generate a new one");
}
};
1 个解决方案
#1
0
$scope.addImage function index variable may be has wrong value and $scope.campaigns[index] is undefined.
$ scope.addImage函数索引变量可能有错误的值,$ scope.campaigns [index]未定义。
if your have ng-repeate loop and ng-click with addImage($index) then on click the function will pass wrong value i.e. $scope.campaigns.length. Please use single campaign object instead of index number.
如果你有ng-repeate循环并使用addImage($ index)进行ng-click,那么单击该函数将传递错误的值,即$ scope.campaigns.length。请使用单个广告系列对象而不是索引号。
The function like
功能就像
$scope.addImage = function (campaign) {
if(!campaign) return;
if ($scope.length < campaign.max_slots) {
$scope.slots.push({
"slot_id": $scope.length + 1,
"base_image": $scope.preview,
"path_image": ""
});
} else {
window.alert("you have to delete a slot to generate a new one");
}
};
更多相关文章
- linux使用rz和sz命令,实现小文件上传下载
- shell脚本let命令在windows下编辑后上传到Linux一直报错
- Linux 上传代码到github
- 双插槽与单插槽内存模型?
- asp.net按路径把图片上传到sql数据库
- 七牛---Android SDK断点续传与暂停上传Demo
- java文件上传输入输出流的问题
- Android——Tomcat版本更新下载+头像照片上传到Tomcat
- Android 打包VersionCode自增、APK文件名修改、上传蒲公英