问题
I'm sure everyone already knows this, but it took me a while to figure out so I thought I would share.
Basically I was trying tell a widget to change color based on the current status of an entry in my model.
But I needed Widget 1 to change for Room 201, Widget 2 to change for Room 202, etc.
Ex:
Room: 201, Status: Available = Widget 1: Green Room: 202, Status: Booked = Widget 2: Red
I could get the widgets to change color (thanks to borrowing from the code in the Project List Sample), but I was confused how to change their individual datasources to a query. They would basically only show the color corresponding to the currently selected item in the database/table.
So, here is what I did:
Went into my Model, went under Datasources and added a new Datasource.
Ex name: Room201
Then in the Query builder I put in the Field I was trying to narrow by.
ex: Room = :Query
(Room = my field, and I believe the ":Query" is the just name of the query, someone can correct me if I'm wrong)
Then you'll see a box below that window where you can add a binding. So THAT is where I put in my query.
ex: @datasources.Facilities.query.filters.Room._equals = 201
(Note: I had to create a separate Datasource for each room)
Then I went to my widget and chose the queried datasource (Room201) for the datasource.
So Widget 1 = the datasource Room201, Widget 2 = the datasource Room202, etc.
Done.
Hopefully that helps someone!
回答1:
Posting the author's (Adam Bergeron) solution to the question as an actual Stack Overflow answer:
" So, here is what I did:
Went into my Model, went under Datasources and added a new Datasource.
Ex name: Room201
Then in the Query builder I put in the Field I was trying to narrow by.
ex: Room = :Query
(Room = my field, and I believe the ":Query" is the just name of the query, someone can correct me if I'm wrong)
Then you'll see a box below that window where you can add a binding. So THAT is where I put in my query.
ex: @datasources.Facilities.query.filters.Room._equals = 201
(Note: I had to create a separate Datasource for each room)
Then I went to my widget and chose the queried datasource (Room201) for the datasource.
So Widget 1 = the datasource Room201, Widget 2 = the datasource Room202, etc.
Done.
Hopefully that helps someone! "
来源:https://stackoverflow.com/questions/41881534/had-trouble-linking-widget-to-a-queried-datasource