Emberjs has not processed anything this action

Error: failed Error: nothing processed the action 'rollDice'. If you performed an action, this error may be caused by the return of truth from the action handler in the controller, as a result of which the action should bubble. I made sure that the method in the controller has the same name as the action. ???

HTML part

    <script type="text/x-handlebars">
     {{outlet}}
    </script>
    <script type="text/x-handlebars" id="index">
     {{#linkTo "roll"}}Lets roll dice!{{/linkTo}}
     </script>
     <script type="text/x-handlebars" id="roll">
        <p class="centerme">A Dice Roller.</p>
    <p>&nbsp;</p>
        <p>Click to play!<br/>
        <button id="play" {{action 'rollDice'}}>Roll Dice</button>
    </p>
    <section id="roll-wrap">Dice stuff</section>
<script>

controller

DiceRoller.RollController = Ember.ObjectController.extend({
    var diceModel = this.get('model');
    actions: {
        rollDice: function () {
            var x=[270,1080,1440,810];
            var rand1=Math.floor(Math.random()*4);
            var rand2=Math.floor(Math.random()*4);

            diceModel.set('rotateXvalue',x[rand1]+"deg");
            diceModel.set('rotateYvalue',x[rand2]+"deg");
            diceModel.save();
        }.property('diceModel.rotateXvalue','diceModel.rotateYvalue')
    }
});

Routing

DiceRoller.Router.map(function() {
    this.resource("roll");
});

DiceRoller.IndexRoute = Ember.Route.extend({
    redirect: function(){
        this.transitionTo("roll");
    }
});

DiceRoller.DiceRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('Dice');
    }
});

Model

DiceRoller.Dice = DS.Model.extend({
rotateXvalue: DS.attr('string'),
rotateYvalue: DS.attr('string')
});

DiceRoller.Dice.FIXTURES = [
{

rotateXvalue: '40deg',
rotateYvalue: '37deg'
}
];

http://jsbin.com/qosujasi/1/ My JS bean, so far it gives me an error in setting the contents of the proxy object.

+4
source share
3 answers

You have incorrectly specified your controller. The correct controller for the logging route will be DiceRoller.RollController.

RollController roleDice, . , .

DiceRoller.RollController = Ember.ObjectController.extend({
    actions: {
        rollDice: function () {
            var diceModel = this.get('model');
            var x=[270,1080,1440,810];
            var rand1=Math.floor(Math.random()*4);
            var rand2=Math.floor(Math.random()*4);

            diceModel.set('rotateXvalue',x[rand1]+"deg");
            diceModel.set('rotateYvalue',x[rand2]+"deg");
            diceModel.save();
        }
    }
});

jsBin.

, , :

DiceRoller.RollRoute = Ember.ObjectController.extend({
    model:function() {
        return this.store.createRecord('dice');
    }
});
+2

, Ember.js, , actions: {...} :

DiceRoller.DiceRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('Dice');
    },
    actions: {...} // move actions here
});

ApplicationController RollController:

DiceRoller.ApplicationController = Ember.ObjectController.extend({
    var diceModel = this.get('model');
    actions: {
        rollDice: function () {
            var x=[270,1080,1440,810];
            var rand1=Math.floor(Math.random()*4);
            var rand2=Math.floor(Math.random()*4);

            diceModel.set('rotateXvalue',x[rand1]+"deg");
            diceModel.set('rotateYvalue',x[rand2]+"deg");
            diceModel.save();
        }.property('diceModel.rotateXvalue','diceModel.rotateYvalue')
    }
});

, ! , - ; -)

+2

Ember " → ", , , ​​ , , . /about.hbs /about.js , . , hbs //, , /about.js:

import Ember from 'ember';

export default Ember.Controller.extend({
isBody: false,
  actions: {
    toggleBody() {
        console.log("Look at me go!");
        this.toggleProperty('isBody');
    }
  }
});

EmberCli, v2.0.0, , , ...

0

Source: https://habr.com/ru/post/1536473/


All Articles