EmberJS - Reliure unidirectionnelle

La liaison de modèle d'objet spécifie les modifications dans une direction à l'aide de la méthode de liaison unidirectionnelle computed.oneWay () et peut être utile lors de la spécification du comportement sur une autre propriété par substitution.

Exemple

L'exemple suivant spécifie le comportement sur une autre propriété en remplaçant -

import Ember from 'ember';

export default function() {
   var CarOne = Ember.Object.create ({
      
      //primary value
      TotalPrice: 860600
   });

   var Car = Ember.Object.extend ({
      TotalPrice: Ember.computed.oneWay('CarOne.TotalPrice')
   });

   var Car = Car.create ({
      CarOne: CarOne
   });
   
   //Changing the user object name, changes the value on the view
   CarOne.set('TotalPrice', 860600);

   //Car.TotalPrice will become "860600"
   Car.set('TotalPrice', 930000);  // changes to the view don't make it back to the object.
   document.write('<h3>One Way Binding<h3>');
   document.write('Value of car : ' + CarOne.get('TotalPrice')); //display value as 860600
}

Ouvrez maintenant le fichier app.js et ajoutez la ligne suivante en haut du fichier -

import objectmodelonewaybinding from './objectmodelonewaybinding';

Où, objectmodelonewaybinding est un nom du fichier spécifié comme "objectmodelonewaybinding.js" et créé dans le dossier "app".

Appelez ensuite le "objectmodelonewaybinding" hérité en bas, avant l'exportation. Il exécute la fonction objectmodelonewaybinding qui est créée dans le fichier objectmodelonewaybinding.js -

objectmodelonewaybinding();

Production

Exécutez le serveur de braises et vous recevrez la sortie suivante -