I think this should be in the $w.onReady()-code-part.
$w('#repeaterUserMaterials').onItemReady(($item, itemData, index)=>{
$item("#titleText").text = itemData.title;
$item("#mainCategoryText").text = itemData.mainCategory;
$item("#subCategoryText").text = itemData.subCategory;
});
$w.onReady(()=>{
});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- your code part + + + + + + + + + + + + + +
-
-
-
-
-
-
-
-
-
-
-
-
-
$w('#repeaterUserMaterials').onItemReady(($item, itemData, index)=>{
$item("#titleText").text = itemData.title;
$item("#mainCategoryText").text = itemData.mainCategory;
$item("#subCategoryText").text = itemData.subCategory;
});
= = = = = = = = = = = = = = = = RESULT = = = = = = = = = = = = = = = = = =
$w.onReady(()=>{
$w('#repeaterUserMaterials').onItemReady(($item, itemData, index)=>{
$item("#titleText").text = itemData.title;
$item("#mainCategoryText").text = itemData.mainCategory;
$item("#subCategoryText").text = itemData.subCategory;
});
});
A REFRESH of DATASET won’t help here, because you populate your REPEATER by CODE and you surely have no CONNECTION between REPEATER and DATASET in the Wix-Property-Panel, don’t you?
A mixing usage of both ways, would cause inteferances (on my opinion).
Either you do everything by code, or you do (almost) everything by a connection in the wix-editor’s property-panel.
But, i think you should go the CODING-way (more flexible).
The same issue here…
The -onAfterSave()-Function should be a stand-alone-function and should not be placed inside another function.
$w("#documentDbInProfile").onAfterSave( () => {
$w("#documentDbInProfile").refresh();
let page = $w("#paginationForUserMaterials").currentPage;
let skipCount = (page - 1) * 10;
getMaterialsByCurrentUserId(skipCount, 10);
})
And another question is: Does onAfter-Save ever do some action?
I am not sure if onAfterSave is running after —>
wixData.save(db, itemToInsert);
Normaly you should use —>
… or …
… to fire up the onAfter-Save-function ( on my opinion).
And now you have reached the point where it starts to be complicated (because of MIXING —> Wix-Data & DATASET -functions).
How to solve your problem.
- You can use a DATASET, but i would disconnect it completely and would connect it just with the related DB. All the rest will be done by code.
- Populating REPEATER —> by CODE.
- Using DATASET to fire up onAfterSave().
This will surely have the one or the other bug, because i did it just the theoretical way and did not test it. You will have to debug it a little bit by your own.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
var DATABASE = "document_db";
var DATASET = "documentDbInProfile"
var DATAFIELD = "_owner";
var LIMIT = 1000; //<---Modify by your own
var SKIP = 100; //<---Modify by your own
$w.onReady(()=>{
$w("#"+DATASET).onReady(()=>{
//-------------------------------------------------------------------
$w('#loadMaterialButton').onClick(()=>{
let loadResult = $w('#loadMaterialResult');
if($w("#uploadFileButton").value.length>0){
$w("#uploadFileButton").startUpload()
.then((uploadedFile) => {
loadResult.text = "Upload successful";
loadResult.show();
resetLoadMaterialFields();
$w("#"+DATASET).setFieldValues({
"title": $w('#subjectInputField').value,
"mainCategory": $w('#mainCategoryMaterialsInProfile').value,
"subCategory": $w('#subCategoryMaterialsInProfile').value,
"documentUrl": uploadedFile.url
});
$w("#"+DATASET).save();
})
.catch( (uploadError) => {
resetLoadMaterialFields();
loadResult.text = "File upload error";
loadResult.show();
console.log("File upload error: " + uploadError.errorCode);
console.log(uploadError.errorDescription);
});
}
});
//-------------------------------------------------------------------
$w("#documentDbInProfile").onAfterSave(() => {
$w("#documentDbInProfile").refresh();
let page = $w("#paginationForUserMaterials").currentPage;
let skipCount = (page - 1) * 10;
getMaterialsByCurrentUserId(skipCount, 10);
});
//-------------------------------------------------------------------
$w('#repeaterUserMaterials').onItemReady(($item, itemData, index)=>{
$item("#titleText").text = itemData.title;
$item("#mainCategoryText").text = itemData.mainCategory;
$item("#subCategoryText").text = itemData.subCategory;
});
});
});
// The only function where i would use Wix-Data...(this is ok).
async function getMaterialsByCurrentUserId(skipNumber, numberLimit){
let VALUE = await wixUsers.currentUser.id
wixData.query(DATABASE)
.eq(DATAFIELD, VALUE)
.skip(SKIP)
.limit(LIMIT)
.descending("_createdDate")
.find()
.then((result)=>{console.log("Here --> populating REPEATER with RESULT-DATA")
$w('#repeaterUserMaterials').data = result.items;
});
}
Or you go the Wix-Data-way, and do not use DATASET.