Ich bin neu zu ember und ich würde gerne eine separate Aktion (shuffle) in einer meiner Aktionen (zuweisen) verwenden. Ich weiß, dass ich hier etwas falsch mache, die Shuffle-Methode macht gar nichts. Rufe ich es falsch an oder sollen Aktionen nicht von anderen Aktionen verwendet werden? Hier ist der Code:Verwenden von Aktionen innerhalb eines Controllers?
import Ember from 'ember';
export default Ember.Controller.extend({
taskData: [],
personData: [],
taskIn: ' ',
personIn: ' ',
actions: {
saveTask() {
const task = this.get("taskIn");
this.taskData.push(task);
},
savePerson()
{
const person = this.get("personIn");
this.personData.push(person);
},
print(){
var taskString;
//this.taskData.remove(0);
for(var i = 0; i < this.taskData.length; i++)
{
taskString = taskString + this.taskData[i];
}
alert(taskString);
//alert(this.personData);
},
shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
},
//algorithm to match up tasks with people
assign(){
var newTaskD = this.shuffle(this.taskData);
var newPersonD = this.shuffle(this.personData);
var taskString = '';
var peopleString = '';
for(var i = 0; i<newTaskD.length; i++)
{
taskString += " " + newTaskD[i];
}
for(var j = 0; j<peopleString.length; j++)
{
peopleString += " " + newPersonD[j];
}
alert(peopleString);
alert(taskString);
}
}
});
Muss die Schnittstelle die Shuffle-Aktion auslösen? Oder versuchen Sie nur, eine Methode einzurichten, die mindestens eine Aktion aufrufen muss? –
Ich versuche das letztere zu tun. – jvangore31