Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework ionic 3输入数据绑定正在更新相同类型的不同数组_Ionic Framework_Ionic3 - Fatal编程技术网

Ionic framework ionic 3输入数据绑定正在更新相同类型的不同数组

Ionic framework ionic 3输入数据绑定正在更新相同类型的不同数组,ionic-framework,ionic3,Ionic Framework,Ionic3,我在ionic 3应用程序的输入数据绑定中遇到问题。只要输入发生更改,即更改相同类型的不同数组的数组值 这是我的HTML <ion-list> <ion-item-sliding *ngFor="let item of storageItem ; index as i"> <div class ="itemList"> <input type="number" [value] ="item.storage

我在ionic 3应用程序的输入数据绑定中遇到问题。只要输入发生更改,即更改相同类型的不同数组的数组值

这是我的HTML

<ion-list>
    <ion-item-sliding *ngFor="let item of storageItem ; index as i">
        <div class ="itemList">

            <input type="number" [value] ="item.storageOrderQuantity"  (blur)="updateInputItemValue(item)"
                             [(ngModel)]="item.storageOrderQuantity" />

        </div>
    </ion-item-sliding>
</ion-list>
storageItem'是'item'的子集


有谁能告诉我们在数据投标时会出现什么错误吗?

您已经提到,存储项是项的子集

您可能已经知道这一点,数组和对象使用按引用赋值的概念。如果你不知道这一点,请阅读下面关于媒体的文章

因此,如果两个数组中的对象相同,则更新一个数组将更新另一个数组

const obj = { name : 'value' };
const arr1 = [1,2,3,obj];
const arr2 = [4,5,6,obj];

obj.name = 'yash'; // both arrays will have updated object
现在,如果希望避免这种情况,那么可以在将对象用于另一个数组之前创建该对象的副本

参考

现在
storageItem
item>id='storageItem'
指向不同的数组。
因此,您的模板现在将只更新
storageItem

在输入中使用不同的对象,使用您正在进行双向绑定的同一个对象…是的,尝试使用不同的对象,但仍然存在相同的问题。尝试删除[value],但其他数组对象仍在更改。我没有在任何地方分配这两个数组(比如:this.item=this.storageItem)。是的,我在更改值时使用了spread运算符。问题是输入更改是双向数据绑定,它在输入更改时直接更改值。您希望更新哪个数组,还是不希望更新哪个数组?我现在很困惑。你能再解释一下吗?如果你不想要双向绑定,只需丢失
ngModel
。storageItem应该得到更新,但每当我在storageItem中更改对象时,同一个Item对象在Item数组中会自动更改。items和storageItem是如何获得其值的?请共享代码
const obj = { name : 'value' };
const arr1 = [1,2,3,obj];
const arr2 = [4,5,6,obj];

obj.name = 'yash'; // both arrays will have updated object
item: Item[] = [
    { id : 'item1', list : [] }, 
    { id : 'item2', list : [] }, 
    { id : 'storageItem', list : [...storageItem] }
];
storageItem: Item[] = [list of storage items];