dynamic

In Swift, how can I use setValueForKey to set the textAlignment property of an object?

拈花ヽ惹草 提交于 2020-01-06 14:41:08
问题 Let's say we define an object like this: let object: AnyObject = { var result = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 50)) result.text = "First Text" result.backgroundColor = UIColor.blueColor() return result }() For this example, I explicitly created a UILabel , but in my actual project I don't know what type of object is created, so I'm just treating the result as AnyObject for this example. The object is just a standard UILabel with text of "First Text" on a blue background

php - Dynamically update Singleton class' value

霸气de小男生 提交于 2020-01-06 14:04:49
问题 This is a followup question to this question If I declare this as a singleton class: // Server.php class Server { private $stopper; private static $instance; public static getInstance() { if(!isset(self::$Server)) self::$Server = new static(); return self::$Server; } public function setStopper() { $this->stopper = TRUE; } public function startServer() { $self = $this; $consumer = new Consumer(); $consumer->onConsume(function($data) use($self, $consumer) { // some processing if($self-

Is it OK/possible to modify instance variables inside an enum declaration?

余生颓废 提交于 2020-01-06 12:42:42
问题 Or, to re-phrase it: can enum types be "mutable"? public enum Foo { ONE,TWO; private String bar; Foo() { this.bar = ""; } String bar() { return bar; } // legal? void bar(String bar) { this.bar = bar; } } I guess if I want to modify it, it's no longer an enum type. Thoughts? 回答1: It's absolutely valid. It's just a really bad idea. Callers are likely to expect the enum to be properly immutable. In some cases you might want to make it "appear" to be immutable, e.g. with caching, while still

Append and call dynamic javascript function with jQuery

半世苍凉 提交于 2020-01-06 08:57:11
问题 Can you create a dynamic javascript function and immediately call it? I already found that you can't use the callback from append. proposed, non working, code: <script type="text/javascript"> var count=1; $(document).ready(function(){ $(".main").append(' <script type="text/javascript">function init'+count+'(){alert("'+count+'");}<'+'/script> '); window['init'+count](); }); </script> <div class="main"></div> Edit: Narrowed it down to a synchronization problem. Placing alert("") between append

YUI Datatable - Get ID of DOM Element after page has loaded and use it in other YUI events

怎甘沉沦 提交于 2020-01-06 08:51:52
问题 Okay so I have a YUI Datatable. Most of it is exactly as the how to guide says to construct it. I have an event that governs changing the rows per page. It's linked to the rows per page drop down element and it saves the value of that drop down as a cookie when the drop down is changed. var onRPPChange1 = YAHOO.util.Event.addListener("yui-pg0-1-rpp24", "change", getRPP_1); The problem is that "yui-pg0-1-rpp24" (the ID of the drop down) changes whenever I make updates to my data table. I would

ElasticSearch - copy_to with dynamic template

↘锁芯ラ 提交于 2020-01-06 08:32:37
问题 Following up my previous question: ElasticSearch overriding mapping from text to object I have an index template: { "template" : "project.*", "order" : 100, "dynamic_templates": [ { "message_field": { "mapping": { "type": "object" }, "match": "message" }, "message_properties": { "path_match": "message.*", "mapping": { "type": "string", "index": "not_analyzed" } } } ] } which basically creates new fields for everything under "message" field. I am doing this because "message" field is mapped as

Error in Dynamic SQL SP

让人想犯罪 __ 提交于 2020-01-06 08:24:13
问题 I Have created a procedure which has code like this: Create PROCEDURE Sample( @ID INT ) AS BEGIN DECLARE @SQL NVARCHAR(max) DECLARE @SchemaName SYSNAME DECLARE @TableName SYSNAME DECLARE @DatabaseName SYSNAME SELECT @SQL = 'Create Table ' + @DatabaseName + '.' + @SchemaName + '.' + @TableName + '_temp' + '(' SELECT @SQL = @SQL + 'ID int NOT NULL Primary Key, Name VarChar(10))' I Always get error as : Msg 102, Level 15, State 1, Line 77 Incorrect syntax near ','. Can anyone help me on this?

How to return List<dynamic> with Dapper.NET ORM that can bindable?

烈酒焚心 提交于 2020-01-06 07:09:52
问题 This question is old now, Dapper data-view binding are fixed as shown answer below :) 回答1: I've added TypeDescriptor -based bindings to DapperRow , which means that anything obtained via Query() (the dynamic API) should now bind to much common UI controls. Anything from 1.60.5 or above should work. Let me know! Caveat: it doesn't currently work for empty results (zero rows). I know how to implement that (see notes here), but that would require some additional changes to the query

How to return List<dynamic> with Dapper.NET ORM that can bindable?

て烟熏妆下的殇ゞ 提交于 2020-01-06 07:09:20
问题 This question is old now, Dapper data-view binding are fixed as shown answer below :) 回答1: I've added TypeDescriptor -based bindings to DapperRow , which means that anything obtained via Query() (the dynamic API) should now bind to much common UI controls. Anything from 1.60.5 or above should work. Let me know! Caveat: it doesn't currently work for empty results (zero rows). I know how to implement that (see notes here), but that would require some additional changes to the query

Why does my dynamically created GroupBox place its RadioButtons too far right on subsequent usages?

核能气质少年 提交于 2020-01-06 07:05:22
问题 I am adding various dynamically created controls to a panel, based on what the user selects. If a Groupbox, with associated RadioButtons, is the first control, it looks fine: ...but if it's anything other than that, the associated radio buttons seem right-aligned instead of left-aligned, as seen above, and the groupbox is too wide, to boot. Here is the pertinent code (RepaintMockupPanel() is called when the user opts to see what his mockup looks like at any time, and getGroupBox() is the