gpt4 book ai didi

javascript - pageLoaded 函数未触发

转载 作者:行者123 更新时间:2023-12-03 00:25:44 27 4
gpt4 key购买 nike

我正在使用 nativescript javascript 平台创建待办事项应用程序。请找到下面的js代码。列出未在着陆页中显示的项目。当我尝试调试 Exports.pageloaded 函数时未触发。请指出代码出了什么问题。如果需要什么,请告诉我。

提前致谢!

var Observable = require("tns-core-modules/data/observable");
var ObservableArray = require("tns-core-modules/data/observable-array");

var pageArray = new ObservableArray.ObservableArray();
var pageData = new Observable.Observable({
notes: pageArray
});

var view = require("tns-core-modules/ui/core/view");

var uiEnums = require("tns-core-modules/ui/enums");
var animation = require("tns-core-modules/ui/animation");

var appSettings = require("application-settings");

var fs = require("file-system");

var page;

var notesArr = [];

var current_index = -1;

exports.pageLoaded = function(args) {
page = args.object;
pageData.set('showForm', true);

var new_note_title = appSettings.getString('new_note_title');
var notes = appSettings.getString('notes');

if(!notes){
notes = [
{
index: 0,
title: '100 push ups'
},
{
index: 1,
title: '100 sit ups'
},
{
index: 2,
title: '100 squats'
},
{
index: 3,
title: '10km running'
}
];

}else{
notes = JSON.parse(notes);
}

notesArr = notes;
if(!pageArray.length){
for(var x = 0; x < notes.length; x++){
current_index += 1;
pageArray.push(notes[x]);
}
}

pageData.set('item_title', new_note_title);
args.object.bindingContext = pageData;

view.getViewById(page, 'form').animate({
translate: { x: 0, y: 160 },
duration: 800,
});
}

exports.newNote = function() {

var showForm = pageData.get('showForm');
var top_position = (showForm) ? -160 : 160;
var list_visibility = (showForm) ? 1 : 0;

view.getViewById(page, 'list').animate({
opacity: list_visibility,
duration: 400
});

view.getViewById(page, 'form').animate({
translate: { x: 0, y: top_position },
duration: 800,
});

pageData.set('showForm', !showForm);
}


exports.btnLoaded = function (args) {
var btn = args.object;
btn.android.setFocusable(false);
}


exports.saveNote = function() {

var new_note_title = pageData.get('item_title');
var new_note_photo = pageData.get('attachment_img');

current_index += 1;
var new_index = current_index;

var new_item = {
index: new_index,
title: new_note_title,
photo: new_note_photo,
show_photo: false
};

notesArr.push(new_item);
pageArray.push(new_item);

appSettings.setString('notes', JSON.stringify(notesArr));

appSettings.setNumber('current_index', new_index);

appSettings.remove('new_note_title');
appSettings.remove('new_note_photo');

pageData.set('showForm', false);
pageData.set('item_title', '');
pageData.set('attachment_img', null);

view.getViewById(page, 'list').animate({
opacity: 1,
duration: 400
});

view.getViewById(page, 'form').animate({
translate: { x: 0, y: -160 },
duration: 800,
});

}

exports.deleteNote = function(args){

var target = args.object;

var index_to_delete = notesArr.map(function(e) {
return e.index;
}).indexOf(target.index);

notesArr.map(function(item, index){

if(index == index_to_delete){
notesArr.splice(index_to_delete, 1);
pageArray.splice(index_to_delete, 1);
return false;
}
});

appSettings.setString('notes', JSON.stringify(notesArr));
}

最佳答案

请找到 Playground here

函数 pageLoaded(args) {
警报('页面已加载');
...
}

最后exports.pageLoaded = pageLoaded;它在加载时弹出警报,并且 pageLoaded 函数被触发。

关于javascript - pageLoaded 函数未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54103323/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com