Had trouble linking widget to a queried datasource

随声附和 提交于 2020-01-05 06:26:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!