这是响应数据。使用按下增量和减量时,我需要为每个项目存储数量。
<!DOCTYPE html>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="Controller">
<br>
<hr>
<select name="main" id="main">
<option value="mainOption">mainOption1</option>
<option value="mainOption">mainOption2</option>
<option value="mainOption">mainOption3</option>
<option value="mainOption">mainOption4</option>
</select>
<hr>
<select name="sub" id="main">
<option value="subOption">subOption1</option>
<option value="subOption">subOption2</option>
<option value="subOption">subOption3</option>
<option value="subOption">subOption4</option>
</select>
<hr>
<select ng-model="selectC" name="subSub" id="main">
<option value="0">subSubOption1</option>
<option value="1">subSubOption2</option>
<option value="2">subSubOption3</option>
<option value="3">subSubOption4</option>
</select>
<hr>
<select ng-if="showDropDownOptions[selectC].indexOf(1) != '-1' && selectC && opt1.length>0" ng-model="selectedName" ng-options="x for x in opt1">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(2) != '-1' && selectC && opt2.length>0" ng-model="selectedName" ng-options="x for x in opt2">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(3) != '-1' && selectC && opt3.length>0" ng-model="selectedName" ng-options="x for x in opt3">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(4) != '-1' && selectC && opt4.length>0" ng-model="selectedName" ng-options="x for x in opt4">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(5) != '-1' && selectC && opt5.length>0" ng-model="selectedName" ng-options="x for x in opt5">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(6) != '-1' && selectC && opt6.length>0" ng-model="selectedName" ng-options="x for x in opt6">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(7) != '-1' && selectC && opt7.length>0" ng-model="selectedName" ng-options="x for x in opt7">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(8) != '-1' && selectC && opt8.length>0" ng-model="selectedName" ng-options="x for x in opt8">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(9) != '-1' && selectC && opt9.length>0" ng-model="selectedName" ng-options="x for x in opt9">
</select>
<select ng-if="showDropDownOptions[selectC].indexOf(10) != '-1' && selectC && opt10.length>0" ng-model="selectedName" ng-options="x for x in opt10">
</select>
</div>
</body>
</html>
Redux状态:在基于对象的存储中保存状态
因此很容易根据密钥进行更新。
{name: "McChicken", type: "Non-Veg", price: 275, tax: 10}
{name: "Pizza", type: "Non-Veg", price: 275, tax: 10}
{name: "Burger", type: "Non-Veg", price: 275, tax: 10}
调用更新和删除项目操作时出错。
错误:未定义cartData
如果响应更新,我如何更新数量并管理状态?
答案 0 :(得分:1)
你需要改变
{ ...state, cartData.name: action.payload }
{ ...state, [cartData.name]: action.payload }