ember.js - getting back reference to a specific model using Ember's Array Controller -


I am new to amber and I see some of their concepts being slightly opaque. I have an app that manages inventory for the company is a screen that gives the complete list of their inventory and allows them to edit each inventory item. Text fields are disabled by default and I want an 'Edit Items' button which will be disabled / disabled / disabled / incorrect.

  Inv.InventoryitemsRoute = Ember.Route.extend ({Model: I have created the renders correctly after that. Function (parameter) {return amber getJSON ("/ arc / v1 / API / inventory_items / "+ params.location_id";} & lt; script type = "text / x-handle" data-template name = "inventoryitems" & gt; {{#each}} & lt; div class = 'row & Lt; p & gt; {{input type = "text" value = header disabled = "true"}}  & lt; p & gt; {{input type = " Text "value = extension disabled =" true "}}  button {{action" editInventoryItem "data-id = id}} & gt; edit item & lt; / butt No & gt; & lt; button {{action "saveInventoryItem" Data-id = id}} & gt; Save & gt; item & gt; & lt; / div & gt; {{/ each}} < / Code> 

So it's okay in the UI, but I'm not sure how to replace the disabled / incorrectly disabled text / text with specific models. If I was just doing this as a normal jQuery, then I would add that ID value to specific ID and input in the input field so that I could set the textfield. Based on reading through the docs, it seems that I want a controller - do I want an arreentroolar for an example of this model or amber can understand myself?

I'm thinking that I want to do something like this but to warn the ID, I undefined :

  Inv.InventoryitemsController = Ember ArrayController.extend ({idating: false, verb: {editInventoryItem: function () {var model = this.get ('model'); / * ^^^ This should be a reference to that specific example of a single model or inventory List of models provided by Root * / Alert ('You want to edit it:' + model.id); // & lt; -fundefined}}};  

Amber In Docs, they use a playlist example like this (here :):

  App.SongsRoute = Ember.Route.extend ({setupController: function (controller, playlist) {controller. Set ('model', playlist.gate ('songs'));}});  

But this example is a bit confusing (for some reasons), but in this particular case - I How would a map list their concept of playlists attempt to edit a list?

OK Is it Well, because you said, you are starting with Amber, maybe I will do this:

   

With this, you define a headerEnabled property in the InventoryitemController (note that it is singular, not all that contains all items), and for detailEnabled, and functions You can also define them either in the same controller or in the path:

  App.InventoryitemController = Ember.ObjectController.extend ({headerEnabled: false, detailEnabled: false, Functions: {editInventoryItem: function () {this.set ('headerEnabled', true); this.set ('detailEnabled', true);}}});  

This is just an example of how you can obtain data, if the same property will enable both text fields, then you need one instead of just two. If 'each' loop does not lift the correct controller, specify the item controller.


Comments