@carlosgomesnc
Ok, your code is a little bit confusing for me and really hard to understand, especialy without knowing your database.
Look here…
You are using this code here to do some kind of RESET right?
You are setting all the repeater values to …
- —>“mes”
- —> 0
But you first generate an object for this —> “itens”, why?
Why not go the DIRECT way?
let itens = [
{"_id":"0001" , "item": "mes", "qtd" : 0}
]
$w("#repAutor").data = itens
$w("#repAutor").forEachItem(($item, itemData)=>{
$item("#txtItem").text = itemData.item
$item("#tbQuantidade").value = itemData.qtd
})
DIRECT-WAY:
$w("#repAutor").forEachItem(($item, itemData)=>{
$item("#txtItem").text = "mes"
$item("#tbQuantidade").value = 0
})
Your button —> “#btnSomar” is outside of repeater?
And even this one makes no sense for me…
$w.onReady(function () {
$w("#repAutor").onItemReady(($item, itemData, index) => {
$item("#txtItem").text = "mes"
$item("#tbQuantidade").value = 0
})
$w("#btnSomar").onClick(()=>{calcular();})
});
function calcular(){
let total
$w("#repAutor").forEachItem(($item, itemData, index)=>{
console.log("itemData--->qtd: ", itemData.qtd)
itemData.qtd = $item("#tbQuantidade").value
total = total + Number(itemData.qtd)
$w("#txtSoma").text = String(total)
})
$w("#txtSoma").expand() //---> just to be sure that this element is expanded and not collapsed
$w("#txtSoma").show('float')
}
Anyway, if your —> “itens”-data is not a reset-function, than it could work…
let itens =[
{"_id":"0001","item":"mesX","qtd":0},
{"_id":"0002","item":"mesY","qtd":22},
{"_id":"0003","item":"mesZ","qtd":3},
{"_id":"0004","item":"mesA","qtd":42},
{"_id":"0005","item":"mesC","qtd":14},
]
Then it would look like this…
let ITEMS =[
{"_id":"0001","item":"mesX","qtd":0},
{"_id":"0002","item":"mesY","qtd":22},
{"_id":"0003","item":"mesZ","qtd":3},
{"_id":"0004","item":"mesA","qtd":42},
{"_id":"0005","item":"mesC","qtd":14},
]
$w.onReady(function () {
$w("#repAutor").data = ITEMS
$w("#repAutor").onItemReady(($item, itemData, index) => {console.log($item._id)
$item("#txtItem").text = $item.item
$item("#tbQuantidade").value = $item.qtd
})
$w("#btnSomar").onClick(()=>{calcular();})
});
function calcular(){
let total
$w("#repAutor").forEachItem(($item, itemData, index)=>{
console.log("itemData--->qtd: ", itemData.qtd)
itemData.qtd = $item("#tbQuantidade").value
total = total + Number(itemData.qtd)
$w("#txtSoma").text = String(total)
console.log(total)
})
$w("#txtSoma").expand() //---> just to be sure that this element is expanded and not collapsed
$w("#txtSoma").show('float')
}
BTW: Take also a look onto the CONSOLE (press F-12 if you are using the chrome-browser) . You can do the same in the wix-editor.
I hope i understood your issue the right way.
Good luck and happy coding.