Girdi alan ve onu bir listeye ekleyen bir Node.js programı üzerinde çalışıyorum. Bu programı terminal üzerinden kullanacağım. Aşağıdaki işlevi yazdım.Sorgu içindeki metin çoğaltılıyor - Node.js
Sorun Alanları:
add: function() {
console.log("What do you want to add to the ToDo List?");
// Starts the prompt
prompt.start();
// Gets input called content
prompt.get(['content'], function(err, result) {
content = result.content
// Pushed content to the list
toDo.list.push(content);
});
O zaman bu anahtar komutu exicutes denir.
switch (command){
case "list":
toDo.print();
break;
case "add":
toDo.add();
break;
}
Sorun, girdiğimde sonraki girdilerden sonraki tüm girdilerdir.
Çıktı:
Bütün Kodu (eğer ihtiyacınız varsa):
var prompt = require('prompt');
// Empty variables that we will use for prompt input
var content = "";
var command = "";
// Exits the program when this variable changes state
var done = false;
// Object that holds all functions and data for the ToDo portion of this program
var toDo = {
// List that everything all ToDos will be stored within
list: ["Example", "Example 2"],
// Print function prints the list
print: function() {
console.log(toDo.list);
},
// The add function should add a value to the list
add: function() {
console.log("What do you want to add to the ToDo List?");
// Starts the prompt
prompt.start();
// Gets input called content
prompt.get(['content'], function(err, result) {
content = result.content
// Pushed content to the list
toDo.list.push(content);
});
}
}
// Main loop
function getCommand() {
// Starts the prompt
prompt.start();
// Ask for name until user inputs "done"
prompt.get(['timeManage'], function(err, result) {
command = result.timeManage;
// Checks if it is equal to exit; if so it exits the program
if (command === 'exit') {
console.log('Thanks for using timeManage.');
} else {
// Checks the remaining commands; if it finds one it executes
switch (command){
case "list":
toDo.print();
break;
case "add":
toDo.add();
break;
}
// Loops the prompt unless the word exit is run
getCommand();
}
});
}
getCommand();
Ps: Ben node.js çaylak Eğer herhangi bir hata nokta eğer öyleyse söyle lütfen am .
sayesinde Taban