Voglio creare un oggetto usando i dati ember, ma non voglio salvarlo finché non chiamo commit. Come posso ottenere questo comportamento?crea un oggetto temporaneo non persistente in Ember-Data
7
A
risposta
4
È possibile utilizzare transaction
, definito transaction.js con i test corrispondenti in transaction_test.js.
vedere un esempio here:
App.store = DS.Store.create(...);
App.User = DS.Model.extend({
name: DS.attr('string')
});
var transaction = App.store.transaction();
transaction.createRecord(App.User, {
name: 'tobias'
});
App.store.commit(); // does not invoke commit
transaction.commit(); // commit on store is invoked
1
chiamata CreateModel invece!
Esempio:
// This is a persisted object (will be saved upon commit)
var persisted = App.store.createRecord(App.Person, { name: "Brohuda" });
// This one is not associated to a store so it will not
var notPersisted = App.store.createModel(App.Person, { name: "Yehuda" });
ho fatto questo http://jsfiddle.net/Qpkz5/269/ per voi.
0
È possibile utilizzare _create
: App.MyModel._create()
- associerà il modello con il proprio gestore di stato, quindi App.store.commit()
non farà nulla.
Tuttavia, _create
è "privato". Penso che ci debba essere un metodo pubblico per questo caso d'uso.
+0
Ecco il problema di Github: https://github.com/emberjs/data/issues/259 –
Problemi correlati
- 1. Come si crea un cookie persistente o non persistente?
- 2. Quando un oggetto ottiene un objectID che non è temporaneo?
- 3. Crea cookie non persistente con FormsAuthenticationTicket
- 4. Come si crea un nome file temporaneo in Erlang?
- 5. Oggetto persistente in C#. NET Servizio Web
- 6. Crea file temporaneo e rimosso automaticamente
- 7. Come verificare che un oggetto modello sia persistente in DB o in un nuovo oggetto?
- 8. Persistente vs non persistente - Quale dovrei usare?
- 9. Crea un nuovo oggetto List in python
- 10. Can std :: function può essere spostato dal riferimento rvalue a un oggetto temporaneo temporaneo?
- 11. Copia Costruttore necessario con oggetto temporaneo
- 12. Hibernate Stupid Question? Aggiorna oggetto persistente
- 13. È possibile utilizzare un oggetto temporaneo per stringhe?
- 14. C++: riferimento const non temporaneo
- 15. Timer C# non temporaneo
- 16. Come posso dire al compilatore di non creare un oggetto temporaneo?
- 17. Come ottenere il valore mappato SingularAttribute di un oggetto persistente?
- 18. SharedPreferences non persistente
- 19. TextInputLayout setErrorEnabled non crea un nuovo oggetto TextView
- 20. Sessione Express non persistente
- 21. Crea un oggetto che non può essere sottoposto a decapaggio
- 22. Aggiornamento errato non persistente
- 23. persistente oggetto Python in memoria per il server nginx/uwsgi
- 24. Crea oggetto da stringa
- 25. Crea associazione vuota nell'ambito di un oggetto
- 26. È un casting primitivo, crea un nuovo oggetto in memoria?
- 27. Come si crea un oggetto TwoLineListItem?
- 28. RabbitMQ in Docker - creazione utente non persistente
- 29. Perché non persistente localStorage in Chrome?
- 30. req.session in veloce-sessione non persistente
Si sta utilizzando 'ember-latest.js' dalla sezione download del repository dati. Questo file è stato caricato 2 mesi fa (2011-01-30) ed è obsoleto. Non ho trovato questo metodo nel codice dal master. – pangratz
Intendo il 'ember-data-latest.js' ... – pangratz
@pangratz ha ragione, non avevo notato che questo era cambiato. Complimenti a lui – Luan