I have to update the value name attribute of my object at particular index. I am having index no and also array. This is my code,
我必须在特定索引处更新对象的值name属性。我有索引号和数组。这是我的代码,
this.menus.forEach(x => {
let temp = this.menus.findIndex(function (item) {
return item.name == 'Cost Center';
});
// this.menus.values[temp].name=this.newCC;
this.menus[temp].name=this.newCC;
console.log("menu temp",temp);
This is my array structure, Array(11)
这是我的数组结构,数组(11)
0:{_id: "5acc9e6320a7d71ab8372120", name: "DashBoard", link: "dashboard", icon: "fa fa-list", key: "dashboard", …}
1: {_id: "5acc9e6320a7d71ab837211f", name: "My Products", link: "print-products", icon: "fa fa-barcode", key: "print-products", …}
2:{sequence: null, key: "my-saved-jobs", icon: "fa fa-file-text-o", link: "my-saved-jobs", name: "My Saved Jobs", …}
3:{sequence: null, key: "my-placed-orders", icon: "fa fa-list-alt", link: "my-placed-orders", name: "My Orders", …}
4:{_id: "5acc9e6320a7d71ab837211b", name: "Site Design Setup", link: "storefront-setup", icon: "fa fa-university", key: "storefront-setup", …}
5:{_id: "5acc9e6320a7d71ab8372118", name: "Reports", link: "reports", icon: "icon-report", key: "reports", …}
6:{_id: "5accb9425241ed3270585b93", name: "Print Service Category", link: "print-service-category", icon: "fa fa-tasks", key: "print-service-category", …}
7:{sequence: null, key: "my-saved-files", icon: "fa fa-floppy-o", link: "my-saved-files", name: "My Saved Files", …}
8:{sequence: null, key: "product-list", icon: "fa fa-list", link: "product-list", name: "Product List", …}
9:{_id: "5acc9e6320a7d71ab8372119", name: "Deal Code", link: "deal- code", icon: "fa fa-university", key: "deal-code", …}
10:{sequence: null, key: "cost-center", icon: "icon-costCenter", link: "cost-center", name: undefined, …}
length:11
can anyone help to solve my issue? Please reply.
任何人都可以帮助解决我的问题吗?请回复。
1 个解决方案
#1
0
Actually I was doing an mistake while writing code, this code should be written where we are getting response from backend i.e within the scope of success response. this is my new code,
实际上我在编写代码时犯了一个错误,这段代码应该写在我们从后端获得响应的地方,即在成功响应的范围内。这是我的新代码,
this.httpService.save(UrlDetails.$getPaymentSetting, client)
.subscribe(response => {
if (response.responseCode == 200) {
let paymentSetting = response.responseData;
console.log("client PAYMENT RESPONSE ",paymentSetting);
if( paymentSetting.paymentOption.customPayment.length != 0){
<------Some Code----->
.
.
this.menus.forEach(x => {
let temp1 = this.menus.findIndex(function (item) {
return item.name == 'Cost Center';
});
let temp2 = this.menus.findIndex(function (item) {
return item.name == 'Deal Code';
});
this.menus[temp1].name= this.newCC;
this.menus[temp2].name= this.newDC;
});
}
})
#1
0
Actually I was doing an mistake while writing code, this code should be written where we are getting response from backend i.e within the scope of success response. this is my new code,
实际上我在编写代码时犯了一个错误,这段代码应该写在我们从后端获得响应的地方,即在成功响应的范围内。这是我的新代码,
this.httpService.save(UrlDetails.$getPaymentSetting, client)
.subscribe(response => {
if (response.responseCode == 200) {
let paymentSetting = response.responseData;
console.log("client PAYMENT RESPONSE ",paymentSetting);
if( paymentSetting.paymentOption.customPayment.length != 0){
<------Some Code----->
.
.
this.menus.forEach(x => {
let temp1 = this.menus.findIndex(function (item) {
return item.name == 'Cost Center';
});
let temp2 = this.menus.findIndex(function (item) {
return item.name == 'Deal Code';
});
this.menus[temp1].name= this.newCC;
this.menus[temp2].name= this.newDC;
});
}
})