问:
Does SQL Server deferred name resolution work for functions?
SQL Server has Deferred Name Resolution feature, read here for details:
https://msdn.microsoft.com/en-us/library/ms190686(v=sql.105).aspx

In that page, all it's talking is stored procedure so it seems Deferred Name Resolution only works for stored procedures and not for functions and I did some testing.

```<code>create or alter function f2(@i int)
returns table
as
    return (select fff from xxx)
go
</code>```

Note the table xxx does not exist. When I execute the above CREATE statement, I got the following message:

Msg 208, Level 16, State 1, Procedure f2, Line 4 [Batch Start Line 22]

  Invalid object name 'xxx'.

It seems that SQL Server instantly found the non-existent table xxx and it proved Deferred Name Resolution doesn't work for functions. However when I slightly change it as follows:

```<code>create or alter function f1(@i int)
returns int
as
begin
    declare @x int;
    select @x = fff from xxx;
    return @x
end
go
</code>```

I can successfully execute it:

```<code>Commands completed successfully.
</code>```

When executing the following statement:

```<code>select dbo.f1(3)
</code>```

I got this error:

Msg 208, Level 16, State 1, Line 34

  Invalid object name 'xxx'.

So here it seems the resolution of the table xxx was deferred. The most important differences between these two cases is the return type. However I can't explain when Deferred Name Resolution will work for functions and when not. Can anyone help me to understand this? Thanks in advance.

答:
It feels like you were looking for understanding of why your particular example didn't work. Quassnoi's answer was correct but didn't offer a reason so I went searching and found this MSDN Social answer by Erland Sommarskog. The interesting part:

However, it does not extend to views and inline-table functions. For
  stored procedures and scalar functions, all SQL Server stores in the
  database is the text of the module. But for views and inline-table
  functions (which are parameterised view by another name) SQL Server
  stores metadata about the columns etc. And that is not possible if the
  table is missing.

Hope that helps with understanding why :-)

EDIT:

I did take some time to confirm Quassnoi's comment that sys.columns as well as several other tables did contain some metadata about the inline function so I am unsure if there is other metadata not written. However I thought I would add a few other notes I was able to find that may help explain in conjunction.

First a quote from Wayne Sheffield's blog:

In the MTVF, you see only an operation called “Table Valued Function”. Everything that it is doing is essentially a black box – something is happening, and data gets returned. For MTVFs, SQL can’t “see” what it is that the MTVF is doing since it is being run in a separate context. What this means is that SQL has to run the MTVF as it is written, without being able to make any optimizations in the query plan to optimize it.

Then from the SQL Server 2016 Exam 70-761 by Itzik Ben-Gan (Skill 3.1):

The reason that it's called an inline function is because SQL Server inlines, or expands, the inner query definition, and constructs an internal query directly against the underlying tables.

So it seems the inline function essentially returns a query and is able to optimize it with the outer query, not allowing the black-box approach and thus not allowing deferred name resolution.

Body:
SQL Server has Deferred Name Resolution feature, read here for details:
https://msdn.microsoft.com/en-us/library/ms190686(v=sql.105).aspx

In that page, all it's talking is stored procedure so it seems Deferred Name Resolution only works for stored procedures and not for functions and I did some testing.

create or alter function f2(@i int)
returns table
as
    return (select fff from xxx)
go

Note the table xxx does not exist. When I execute the above CREATE statement, I got the following message:

Msg 208, Level 16, State 1, Procedure f2, Line 4 [Batch Start Line 22]

  Invalid object name 'xxx'.

It seems that SQL Server instantly found the non-existent table xxx and it proved Deferred Name Resolution doesn't work for functions. However when I slightly change it as follows:

create or alter function f1(@i int)
returns int
as
begin
    declare @x int;
    select @x = fff from xxx;
    return @x
end
go

I can successfully execute it:

Commands completed successfully.

When executing the following statement:

select dbo.f1(3)

I got this error:

Msg 208, Level 16, State 1, Line 34

  Invalid object name 'xxx'.

So here it seems the resolution of the table xxx was deferred. The most important differences between these two cases is the return type. However I can't explain when Deferred Name Resolution will work for functions and when not. Can anyone help me to understand this? Thanks in advance.


来源: stackexchange

问:
SQL deadlock with select/update operations on a table
I have changed the column(prod_id) datatype "nvarchar(25)" to "varchar(50)" then parallel DML operations are failing with deadlock.

The table involved in deadlock - "tbl_Ref_Attr_Prod_Team "
Indexes on table

Indexes on table

Here is the select/update deadlock xml..

```<code><deadlock>
 <victim-list>
  <victimProcess id="process3980de4558" />
 </victim-list>
 <process-list>
  <process id="process3980de4558" taskpriority="0" logused="0" waitresource="PAGE: 7:1:1660625 " waittime="966" ownerId="635070687" transactionname="SELECT" lasttranstarted="2017-11-14T04:09:08.120" XDES="0x19f7d80040" lockMode="IS" schedulerid="6" kpid="23696" status="suspended" spid="121" sbid="0" ecid="1" priority="0" trancount="0" lastbatchstarted="2017-11-14T02:12:22.280" lastbatchcompleted="2017-11-14T02:12:22.280" lastattention="1900-01-01T00:00:00.280" clientapp=".Net SqlClient Data Provider" hostname="GADC-WMGXSQLP01" hostpid="16128" isolationlevel="read committed (2)" xactid="635070687" currentdb="7" lockTimeout="4294967295" clientoption1="671088928" clientoption2="119832">
   <executionStack>
    <frame procname="adhoc" line="1" stmtstart="112" sqlhandle="0x020000008925110aeb7cb1c1c073dab88fd24fca1951ea9d0000000000000000000000000000000000000000">
select @existing = team_it_cube_attr_05 from tbl_Ref_Attr_Prod_Team where prod_id = @rec_key    </frame>
    <frame procname="mssqlsystemresource.sys.sp_executesql" line="1" stmtstart="-1" sqlhandle="0x0400ff7f427f99d9010000000000000000000000000000000000000000000000000000000000000000000000">
sp_executesql    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_get_attr_value" line="30" stmtstart="2266" stmtend="2438" sqlhandle="0x03000700b694bf1125f34901f9a1000001000000000000000000000000000000000000000000000000000000">
EXECUTE @return_code = sp_executesql @SQL, @ParamDefinition, @item_key, @value OUTPUT    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_validate_category_role" line="146" stmtstart="12864" stmtend="13140" sqlhandle="0x030007005220010817f24901f9a1000001000000000000000000000000000000000000000000000000000000">
exec sp_datman_get_attr_value @attr_id, @item_key, @value OUTPUT

  --if attr is required, make sure it has been supplied    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_validate_category" line="12" stmtstart="892" sqlhandle="0x030007008b44f50851f24901f9a1000001000000000000000000000000000000000000000000000000000000">
exec sp_datman_validate_category_role @geo_id, @category_id, 30, @unvalidated_records_only    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_validate_country_segmentation" line="33" stmtstart="1894" stmtend="2110" sqlhandle="0x030007005bcf6449a3f34901f9a1000001000000000000000000000000000000000000000000000000000000">
exec sp_datman_validate_category @geo_id, @category_id, @unvalidated_records_only

    --fetch next record    </frame>
    <frame procname="adhoc" line="1" sqlhandle="0x010005005563e60c10dab88f0b00000000000000000000000000000000000000000000000000000000000000">
[WMGDS_Ref].[dbo].[sp_datman_validate_country_segmentation] '124'    </frame>
    <frame procname="WGDS_Master.dbo.spWGDSFileProcessor_CustomAction_WDIM_Export_Prod_WM" line="95" stmtstart="7378" stmtend="7420" sqlhandle="0x03000500d1db545fa59ca800d8a3000001000000000000000000000000000000000000000000000000000000">
EXEC(@SQL)    </frame>
    <frame procname="WGDS_Master.dbo.spWGDSFileProcessor_FinalizeLoad" line="30" stmtstart="2380" stmtend="2460" sqlhandle="0x03000500822a3374004032001ca8000001000000000000000000000000000000000000000000000000000000">
EXEC @SQL @LoadID    </frame>
    <frame procname="adhoc" line="1" sqlhandle="0x010005009ab97c38301aa2840a00000000000000000000000000000000000000000000000000000000000000">
EXEC spWGDSFileProcessor_FinalizeLoad 9389    </frame>
   </executionStack>
   <inputbuf>
EXEC spWGDSFileProcessor_FinalizeLoad 9389   </inputbuf>
  </process>
  <process id="process386ed48188" taskpriority="0" logused="38816080" waitresource="PAGE: 7:1:1593417 " waittime="822" ownerId="635069358" transactionname="test" lasttranstarted="2017-11-14T04:09:05.813" XDES="0x7109e3a10" lockMode="X" schedulerid="5" kpid="20156" status="suspended" spid="61" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2017-11-14T04:09:05.043" lastbatchcompleted="2017-11-14T04:05:04.870" lastattention="1900-01-01T00:00:00.870" clientapp="Microsoft SQL Server Management Studio - Query" hostname="BDC-WMGXSQLD01" hostpid="68396" loginname="AP\mandalapu.s.1" isolationlevel="read committed (2)" xactid="635069358" currentdb="7" lockTimeout="4294967295" clientoption1="671091040" clientoption2="390200">
   <executionStack>
    <frame procname="adhoc" line="5" stmtstart="86" sqlhandle="0x02000000b91ca9120ff55e660725b95775c8d18d8bff60d30000000000000000000000000000000000000000">
UPDATE
    D
SET
    D.team_rss_attr_01 = LEFT(S.mkt_prodchar_13,25)
    ,D.team_rss_attr_02 = LEFT(S.mkt_prodchar_14,25)
    ,D.team_rss_attr_03 = LEFT(S.mkt_prodchar_15,25)
    ,D.team_rss_attr_04 = LEFT(S.mkt_prodchar_16,25)
    ,D.team_rss_attr_05 = LEFT(S.mkt_prodchar_17,25)
    ,D.team_rss_attr_08 = LEFT(S.mkt_prodchar_19,25)
FROM
    tbl_Ref_Prod P
    INNER JOIN tblWGDS_Ref_Prod_Market S ON S.prod_key=P.prod_key
    INNER JOIN tbl_Ref_Attr_Prod_Team D ON D.prod_key=P.prod_key
WHERE
    P.geo_id='840'
    AND P.prod_type_id=1    </frame>
   </executionStack>
   <inputbuf>
select @@SPID

begin transaction test

UPDATE
    D
SET
    D.team_rss_attr_01 = LEFT(S.mkt_prodchar_13,25)
    ,D.team_rss_attr_02 = LEFT(S.mkt_prodchar_14,25)
    ,D.team_rss_attr_03 = LEFT(S.mkt_prodchar_15,25)
    ,D.team_rss_attr_04 = LEFT(S.mkt_prodchar_16,25)
    ,D.team_rss_attr_05 = LEFT(S.mkt_prodchar_17,25)
    ,D.team_rss_attr_08 = LEFT(S.mkt_prodchar_19,25)
FROM
    tbl_Ref_Prod P
    INNER JOIN tblWGDS_Ref_Prod_Market S ON S.prod_key=P.prod_key
    INNER JOIN tbl_Ref_Attr_Prod_Team D ON D.prod_key=P.prod_key
WHERE
    P.geo_id='840'
    AND P.prod_type_id=1    </inputbuf>
  </process>
 </process-list>
 <resource-list>
  <pagelock fileid="1" pageid="1660625" dbid="7" subresource="FULL" objectname="WMGDS_Ref.dbo.tbl_Ref_Attr_Prod_Team" id="lock16e2f2b280" mode="X" associatedObjectId="72057594191085568">
   <owner-list>
    <owner id="process386ed48188" mode="X" />
   </owner-list>
   <waiter-list>
    <waiter id="process3980de4558" mode="IS" requestType="wait" />
   </waiter-list>
  </pagelock>
  <pagelock fileid="1" pageid="1593417" dbid="7" subresource="FULL" objectname="WMGDS_Ref.dbo.tbl_Ref_Attr_Prod_Team" id="lock18db89be00" mode="U" associatedObjectId="72057594191085568">
   <owner-list>
    <owner id="process3980de4558" mode="IS" />
   </owner-list>
   <waiter-list>
    <waiter id="process386ed48188" mode="X" requestType="convert" />
   </waiter-list>
  </pagelock>
 </resource-list>
</deadlock>
</code>```

I'm not familiar with SQL deadlocks, so any help would be appreciated....

答:
The two queries causing the deadlock are the SELECT below (process id="process3980de4558"):

```<code>select @existing = team_it_cube_attr_05 from tbl_Ref_Attr_Prod_Team where prod_id = @rec_key
</code>```

And the UPDATE query below (process id="process386ed48188"):

```<code>UPDATE D
SET D.team_rss_attr_01 = LEFT(S.mkt_prodchar_13,25)...
</code>```

The <resource-list> section notes the SELECT query owned an exclusive (X) lock on a page and was trying to acquire an intent-shared (IS) lock on another page while it was reading data.  The UPDATE query already owned an IS lock and was tryign to acquire an X lock on a page to perform the update.

Given the join against this table:

```<code>...from tbl_Ref_Attr_Prod_Team where prod_id = @rec_key...
...INNER JOIN tbl_Ref_Attr_Prod_Team D ON D.prod_key=P.prod_key...
</code>```

The SELECT query already owns an exclusive lock.  This probably means that it is part of a larger transaction that has already performed an UPDATE in a prior query.  Locks from prior queries will be maintained to preserve data integrity during the transaction (depending on the transaction isolation level).

The UPDATE query needs to read the table tbl_Ref_Attr_Prod_team.  It acquires intent-shared locks on pages and rows while reading data.  When the UPDATE query finds the matching rows, it will attempt to convert the IS locks into X locks.  IS locks are not compatible with X locks.  Because the SELECT query already has an IS lock on one or more of those pages, the queries deadlock with each other.

One possible cause would be missing indexes on tbl_Ref_Attr_Prod_team.prod_key.  Without an index on this column, the UPDATE query will be scanning all of the rows in the table tbl_Ref_Attr_Prod_team.

Even if an index exists on prod_key, if there are a small number of rows in the table, SQL Server may decide that performance would be better if the query scanned the entire table instead of seeking the index.  Recording the query plan when the deadlock occurs would verify this theory.

We encounter small table deadlocks regularly when staging new databases.  Initially, the tables are tiny, and table scans cause all sorts of deadlocks.  Later, when the tables are larger, the calculated cost of scanning the table exceeds the cost of seeking the index, and the deadlocks no longer occur.  In test environments where the number of rows is forever small, we have resorted to using FORESEEK and WITH INDEX hints to force index seeks instead of scans.  We are looking forward to being able to force query plans via the query store feature of SQL Server 2016.

ContentLicense: CC BY-SA 3.0

Body:
I have changed the column(prod_id) datatype "nvarchar(25)" to "varchar(50)" then parallel DML operations are failing with deadlock.

The table involved in deadlock - "tbl_Ref_Attr_Prod_Team "
Indexes on table

Indexes on table

Here is the select/update deadlock xml..

<deadlock>
 <victim-list>
  <victimProcess id="process3980de4558" />
 </victim-list>
 <process-list>
  <process id="process3980de4558" taskpriority="0" logused="0" waitresource="PAGE: 7:1:1660625 " waittime="966" ownerId="635070687" transactionname="SELECT" lasttranstarted="2017-11-14T04:09:08.120" XDES="0x19f7d80040" lockMode="IS" schedulerid="6" kpid="23696" status="suspended" spid="121" sbid="0" ecid="1" priority="0" trancount="0" lastbatchstarted="2017-11-14T02:12:22.280" lastbatchcompleted="2017-11-14T02:12:22.280" lastattention="1900-01-01T00:00:00.280" clientapp=".Net SqlClient Data Provider" hostname="GADC-WMGXSQLP01" hostpid="16128" isolationlevel="read committed (2)" xactid="635070687" currentdb="7" lockTimeout="4294967295" clientoption1="671088928" clientoption2="119832">
   <executionStack>
    <frame procname="adhoc" line="1" stmtstart="112" sqlhandle="0x020000008925110aeb7cb1c1c073dab88fd24fca1951ea9d0000000000000000000000000000000000000000">
select @existing = team_it_cube_attr_05 from tbl_Ref_Attr_Prod_Team where prod_id = @rec_key    </frame>
    <frame procname="mssqlsystemresource.sys.sp_executesql" line="1" stmtstart="-1" sqlhandle="0x0400ff7f427f99d9010000000000000000000000000000000000000000000000000000000000000000000000">
sp_executesql    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_get_attr_value" line="30" stmtstart="2266" stmtend="2438" sqlhandle="0x03000700b694bf1125f34901f9a1000001000000000000000000000000000000000000000000000000000000">
EXECUTE @return_code = sp_executesql @SQL, @ParamDefinition, @item_key, @value OUTPUT    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_validate_category_role" line="146" stmtstart="12864" stmtend="13140" sqlhandle="0x030007005220010817f24901f9a1000001000000000000000000000000000000000000000000000000000000">
exec sp_datman_get_attr_value @attr_id, @item_key, @value OUTPUT

  --if attr is required, make sure it has been supplied    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_validate_category" line="12" stmtstart="892" sqlhandle="0x030007008b44f50851f24901f9a1000001000000000000000000000000000000000000000000000000000000">
exec sp_datman_validate_category_role @geo_id, @category_id, 30, @unvalidated_records_only    </frame>
    <frame procname="WMGDS_Ref.dbo.sp_datman_validate_country_segmentation" line="33" stmtstart="1894" stmtend="2110" sqlhandle="0x030007005bcf6449a3f34901f9a1000001000000000000000000000000000000000000000000000000000000">
exec sp_datman_validate_category @geo_id, @category_id, @unvalidated_records_only

    --fetch next record    </frame>
    <frame procname="adhoc" line="1" sqlhandle="0x010005005563e60c10dab88f0b00000000000000000000000000000000000000000000000000000000000000">
[WMGDS_Ref].[dbo].[sp_datman_validate_country_segmentation] '124'    </frame>
    <frame procname="WGDS_Master.dbo.spWGDSFileProcessor_CustomAction_WDIM_Export_Prod_WM" line="95" stmtstart="7378" stmtend="7420" sqlhandle="0x03000500d1db545fa59ca800d8a3000001000000000000000000000000000000000000000000000000000000">
EXEC(@SQL)    </frame>
    <frame procname="WGDS_Master.dbo.spWGDSFileProcessor_FinalizeLoad" line="30" stmtstart="2380" stmtend="2460" sqlhandle="0x03000500822a3374004032001ca8000001000000000000000000000000000000000000000000000000000000">
EXEC @SQL @LoadID    </frame>
    <frame procname="adhoc" line="1" sqlhandle="0x010005009ab97c38301aa2840a00000000000000000000000000000000000000000000000000000000000000">
EXEC spWGDSFileProcessor_FinalizeLoad 9389    </frame>
   </executionStack>
   <inputbuf>
EXEC spWGDSFileProcessor_FinalizeLoad 9389   </inputbuf>
  </process>
  <process id="process386ed48188" taskpriority="0" logused="38816080" waitresource="PAGE: 7:1:1593417 " waittime="822" ownerId="635069358" transactionname="test" lasttranstarted="2017-11-14T04:09:05.813" XDES="0x7109e3a10" lockMode="X" schedulerid="5" kpid="20156" status="suspended" spid="61" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2017-11-14T04:09:05.043" lastbatchcompleted="2017-11-14T04:05:04.870" lastattention="1900-01-01T00:00:00.870" clientapp="Microsoft SQL Server Management Studio - Query" hostname="BDC-WMGXSQLD01" hostpid="68396" loginname="AP\mandalapu.s.1" isolationlevel="read committed (2)" xactid="635069358" currentdb="7" lockTimeout="4294967295" clientoption1="671091040" clientoption2="390200">
   <executionStack>
    <frame procname="adhoc" line="5" stmtstart="86" sqlhandle="0x02000000b91ca9120ff55e660725b95775c8d18d8bff60d30000000000000000000000000000000000000000">
UPDATE
    D
SET
    D.team_rss_attr_01 = LEFT(S.mkt_prodchar_13,25)
    ,D.team_rss_attr_02 = LEFT(S.mkt_prodchar_14,25)
    ,D.team_rss_attr_03 = LEFT(S.mkt_prodchar_15,25)
    ,D.team_rss_attr_04 = LEFT(S.mkt_prodchar_16,25)
    ,D.team_rss_attr_05 = LEFT(S.mkt_prodchar_17,25)
    ,D.team_rss_attr_08 = LEFT(S.mkt_prodchar_19,25)
FROM
    tbl_Ref_Prod P
    INNER JOIN tblWGDS_Ref_Prod_Market S ON S.prod_key=P.prod_key
    INNER JOIN tbl_Ref_Attr_Prod_Team D ON D.prod_key=P.prod_key
WHERE
    P.geo_id='840'
    AND P.prod_type_id=1    </frame>
   </executionStack>
   <inputbuf>
select @@SPID

begin transaction test

UPDATE
    D
SET
    D.team_rss_attr_01 = LEFT(S.mkt_prodchar_13,25)
    ,D.team_rss_attr_02 = LEFT(S.mkt_prodchar_14,25)
    ,D.team_rss_attr_03 = LEFT(S.mkt_prodchar_15,25)
    ,D.team_rss_attr_04 = LEFT(S.mkt_prodchar_16,25)
    ,D.team_rss_attr_05 = LEFT(S.mkt_prodchar_17,25)
    ,D.team_rss_attr_08 = LEFT(S.mkt_prodchar_19,25)
FROM
    tbl_Ref_Prod P
    INNER JOIN tblWGDS_Ref_Prod_Market S ON S.prod_key=P.prod_key
    INNER JOIN tbl_Ref_Attr_Prod_Team D ON D.prod_key=P.prod_key
WHERE
    P.geo_id='840'
    AND P.prod_type_id=1    </inputbuf>
  </process>
 </process-list>
 <resource-list>
  <pagelock fileid="1" pageid="1660625" dbid="7" subresource="FULL" objectname="WMGDS_Ref.dbo.tbl_Ref_Attr_Prod_Team" id="lock16e2f2b280" mode="X" associatedObjectId="72057594191085568">
   <owner-list>
    <owner id="process386ed48188" mode="X" />
   </owner-list>
   <waiter-list>
    <waiter id="process3980de4558" mode="IS" requestType="wait" />
   </waiter-list>
  </pagelock>
  <pagelock fileid="1" pageid="1593417" dbid="7" subresource="FULL" objectname="WMGDS_Ref.dbo.tbl_Ref_Attr_Prod_Team" id="lock18db89be00" mode="U" associatedObjectId="72057594191085568">
   <owner-list>
    <owner id="process3980de4558" mode="IS" />
   </owner-list>
   <waiter-list>
    <waiter id="process386ed48188" mode="X" requestType="convert" />
   </waiter-list>
  </pagelock>
 </resource-list>
</deadlock>

I'm not familiar with SQL deadlocks, so any help would be appreciated....

Body:
The two queries causing the deadlock are the SELECT below (process id="process3980de4558"):

select @existing = team_it_cube_attr_05 from tbl_Ref_Attr_Prod_Team where prod_id = @rec_key

And the UPDATE query below (process id="process386ed48188"):

UPDATE D
SET D.team_rss_attr_01 = LEFT(S.mkt_prodchar_13,25)...

The <resource-list> section notes the SELECT query owned an exclusive (X) lock on a page and was trying to acquire an intent-shared (IS) lock on another page while it was reading data.  The UPDATE query already owned an IS lock and was tryign to acquire an X lock on a page to perform the update.

Given the join against this table:

...from tbl_Ref_Attr_Prod_Team where prod_id = @rec_key...
...INNER JOIN tbl_Ref_Attr_Prod_Team D ON D.prod_key=P.prod_key...

The SELECT query already owns an exclusive lock.  This probably means that it is part of a larger transaction that has already performed an UPDATE in a prior query.  Locks from prior queries will be maintained to preserve data integrity during the transaction (depending on the transaction isolation level).

The UPDATE query needs to read the table tbl_Ref_Attr_Prod_team.  It acquires intent-shared locks on pages and rows while reading data.  When the UPDATE query finds the matching rows, it will attempt to convert the IS locks into X locks.  IS locks are not compatible with X locks.  Because the SELECT query already has an IS lock on one or more of those pages, the queries deadlock with each other.

One possible cause would be missing indexes on tbl_Ref_Attr_Prod_team.prod_key.  Without an index on this column, the UPDATE query will be scanning all of the rows in the table tbl_Ref_Attr_Prod_team.

Even if an index exists on prod_key, if there are a small number of rows in the table, SQL Server may decide that performance would be better if the query scanned the entire table instead of seeking the index.  Recording the query plan when the deadlock occurs would verify this theory.

We encounter small table deadlocks regularly when staging new databases.  Initially, the tables are tiny, and table scans cause all sorts of deadlocks.  Later, when the tables are larger, the calculated cost of scanning the table exceeds the cost of seeking the index, and the deadlocks no longer occur.  In test environments where the number of rows is forever small, we have resorted to using FORESEEK and WITH INDEX hints to force index seeks instead of scans.  We are looking forward to being able to force query plans via the query store feature of SQL Server 2016.


问:
Referring to the triggering object in the done() block of a post() call?
I have a post() call bound to the click() method of a group of images.

Inside the post() call I can refer to jQuery(this) and with that get access to the originating object. (e.g. data parameters, or change its status):

```<code>jQuery('.vote .magic_button').click(function() {
  jQuery.post(url, {
      action: 'ajax_vote',
      'vote_target': jQuery(this).data('postid')
    })
    .done(function(data) {
      // $img = jQuery(this).find('img');
    })
});
</code>```

When the AJAX call returns, after verifying the response, I want to refer to the image that was originally clicked, but that is no longer this in this new context.

How can I access this without having to pass the info back inside the data argument?

答:
You can use the var that = this workaround or just use ES5 .bind function to set the this correctly!

```<code>jQuery('.vote .magic_button').click(function() {
  jQuery.post(url, {
      action: 'ajax_vote',
      'vote_target': jQuery(this).data('postid')
    })
    .done(function(data) {
      // $img = jQuery(this).find('img');
    }.bind(this))
});
</code>```

Documentation

Body:
I have a post() call bound to the click() method of a group of images.

Inside the post() call I can refer to jQuery(this) and with that get access to the originating object. (e.g. data parameters, or change its status):

jQuery('.vote .magic_button').click(function() {
  jQuery.post(url, {
      action: 'ajax_vote',
      'vote_target': jQuery(this).data('postid')
    })
    .done(function(data) {
      // $img = jQuery(this).find('img');
    })
});

When the AJAX call returns, after verifying the response, I want to refer to the image that was originally clicked, but that is no longer this in this new context.

How can I access this without having to pass the info back inside the data argument?

Body:
You can use the var that = this workaround or just use ES5 .bind function to set the this correctly!

jQuery('.vote .magic_button').click(function() {
  jQuery.post(url, {
      action: 'ajax_vote',
      'vote_target': jQuery(this).data('postid')
    })
    .done(function(data) {
      // $img = jQuery(this).find('img');
    }.bind(this))
});

Documentation


问:
how to only allow letters to be used python statment
I'm making a Morse code program:

```<code>def main ():

    morse_code = {"a":".-","b":"-...","c":"-.-.","d":"-..","e":".","f":"..-.","g":"--.","h":"....","i":"..","j":".---","k":"-.-","l":".-..",
                  "m":"--","n":"-.","o":"---","p":".--.","q":"--.-","r":".-.","s":"...","t":"-","u":"..-","v":"...-","w":".--","x":"-..-","y":"-.--","z":"--.."}

    phrase = input("please enter your word or words: ")
    for key in phrase:
        print("your word or sentence translated to morse code is : ")
        print(morse_code[key], end = " ")
    if phrase == int or float:
        print("try the input")

    retry()
def retry ():
    main()
retry()
main()
</code>```

How do I print an error if someone enters a number?

答:
You can use str.isdigit

```<code>for key in phrase:
    if not key.isdigit():
        print("your word or sentence translated to morse code is : ")
        print(morse_code[key], end = " ")
</code>```

Body:
I'm making a Morse code program:

def main ():

    morse_code = {"a":".-","b":"-...","c":"-.-.","d":"-..","e":".","f":"..-.","g":"--.","h":"....","i":"..","j":".---","k":"-.-","l":".-..",
                  "m":"--","n":"-.","o":"---","p":".--.","q":"--.-","r":".-.","s":"...","t":"-","u":"..-","v":"...-","w":".--","x":"-..-","y":"-.--","z":"--.."}

    phrase = input("please enter your word or words: ")
    for key in phrase:
        print("your word or sentence translated to morse code is : ")
        print(morse_code[key], end = " ")
    if phrase == int or float:
        print("try the input")

    retry()
def retry ():
    main()
retry()
main()

How do I print an error if someone enters a number?

Body:
You can use str.isdigit

for key in phrase:
    if not key.isdigit():
        print("your word or sentence translated to morse code is : ")
        print(morse_code[key], end = " ")


问:
Angular: Catch a 404 error on file not found
In my Ionic project I am creating a function to find out if a file exists locally or not. I have created the following function:

```<code>$rootScope.eventFieldTemplateExists = function(field) {
    //var templateUrl = 'views/fields/' + field.name + '.html';
    var templateUrl = 'views/fields/testfile.html';

    $http.head(templateUrl).then(function(res) {
      console.log("success");
      console.log(res);
    })
    .catch(function(err) {
      console.log("catch");
      console.log(err);
    });

    return true;
};
</code>```

The file testfile.html does not exist. The above works fine when I enter a file that do exist, but I still get a console error when the file does not exist:

```<code>HEAD http://localhost:9000/views/fields/testfile.html 404 (Not Found)
catch
{data: "", status: 404, config: {…}, statusText: "Not Found", headers: ƒ}
</code>```

Is there some way to suppress the error? I was hoping that the .catch would suppress it, but apparently it does not.

答:
A response with status 404 will invoke the promise's rejection handler, this is the expected behavior, but your code does not include it so control goes strait to .catch.

Include a rejection handler and resolve the response .when

```<code>$http.head(templateUrl).then(function(res) {
    // this will run for status 2xx
    console.log("success");
    console.log(res);
}, function(response) {
    // this will run for status 4xx, 5xx, etc..
    if (response.status === 404) {
        return $q.when("404: file not found, but it's ok")
    }
    return $q.reject(response);
})
.catch(function(err) {
  console.log("catch");
  console.log(err);
});
</code>```

Body:
In my Ionic project I am creating a function to find out if a file exists locally or not. I have created the following function:

$rootScope.eventFieldTemplateExists = function(field) {
    //var templateUrl = 'views/fields/' + field.name + '.html';
    var templateUrl = 'views/fields/testfile.html';

    $http.head(templateUrl).then(function(res) {
      console.log("success");
      console.log(res);
    })
    .catch(function(err) {
      console.log("catch");
      console.log(err);
    });

    return true;
};

The file testfile.html does not exist. The above works fine when I enter a file that do exist, but I still get a console error when the file does not exist:

HEAD http://localhost:9000/views/fields/testfile.html 404 (Not Found)
catch
{data: "", status: 404, config: {…}, statusText: "Not Found", headers: ƒ}

Is there some way to suppress the error? I was hoping that the .catch would suppress it, but apparently it does not.

Body:
A response with status 404 will invoke the promise's rejection handler, this is the expected behavior, but your code does not include it so control goes strait to .catch.

Include a rejection handler and resolve the response .when

$http.head(templateUrl).then(function(res) {
    // this will run for status 2xx
    console.log("success");
    console.log(res);
}, function(response) {
    // this will run for status 4xx, 5xx, etc..
    if (response.status === 404) {
        return $q.when("404: file not found, but it's ok")
    }
    return $q.reject(response);
})
.catch(function(err) {
  console.log("catch");
  console.log(err);
});


问:
PostgreSQL recompile needed after upgrading to a quad-core CPU?
I recently upgraded my server running CentOS 5.0 to a quad-core CPU from a dual-core CPU. Do I need a recompile to make use of the added cores? PostgreSQL was installed by compiling from source.

EDIT: The upgrade was from an Intel Xeon 5130 to an Intel Xeon 5345.

答: Presumably both the old and new chips are running x86_64 architecture. No recompile is necessary, however some tuning of the database and/or application might be to fully use those extra cores.</p>

OwnerDisplayName: Radamanthus

ContentLicense: CC BY-SA 2.5

LastEditorDisplayName: Radamanthus

OwnerDisplayName: MarkR


问:
Compiler design, creating a language. How?
The Dragon book
is a famous book for designing a compiler. Is there another book like that or a great article about that? And what're the keywords about compilers? I wanna know how a new language is created.</p>

答:
If you are willing to go .NET:
http://www.amazon.com/Build-Your-NET-Language-Compiler/dp/1590591348</p>


问:
index.ts is not part of the compilation output
I am trying to compile my Angular application and am getting an error.
It seems to be with the compiler not recognizing the index.ts file. I'm not sure why.

Below is the error:

```<code>ERROR in ./node_modules/datatable/index.ts
Module build failed: Error: node_modules\datatable\index.ts is not part of the compilation output. Please check the other error messages for details.
    at AngularCompilerPlugin.getCompiledFile (node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:629:23)
    at plugin.done.then (node_modules\@ngtools\webpack\src\loader.js:467:39)
    at process._tickCallback (internal/process/next_tick.js:103:7)
 @ ./src/main/ui/app/app.module.ts 13:0-59
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
ERROR in ./node_modules/typeahead/index.ts
Module build failed: Error: node_modules\typeahead\index.ts is not part of the compilation output. Please check the other error messages for details.
    at AngularCompilerPlugin.getCompiledFile (\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:629:23)
    at plugin.done.then (node_modules\@ngtools\webpack\src\loader.js:467:39)
    at process._tickCallback (internal/process/next_tick.js:103:7)
 @ ./src/main/ui/app/app.module.ts 12:0-59
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
</code>```

Does anyone have any suggestions on how to fix this?
Thank you.

答:
I had a similar issue with angular-bootstrap-md\index.ts

how I could fix it:

Just put the index.ts file to the tsconfig.jsons include block ,
  see below:

```<code>{
  "compileOnSave": false,
  "compilerOptions": {
  "outDir": "./dist/out-tsc",
  "sourceMap": true,
  "declaration": false,
  "moduleResolution": "node",
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "target": "es5",
  "typeRoots": [
    "node_modules/@types"
  ],
  "lib": [
    "es2017",
    "dom"
  ]
},
"include": [
  "src/**/*",
  "node_modules/angular-bootstrap-md/index.ts"
  ]
 }
</code>```

Source: https://github.com/angular/angular/issues/20091

Body:
I am trying to compile my Angular application and am getting an error.
It seems to be with the compiler not recognizing the index.ts file. I'm not sure why.

Below is the error:

ERROR in ./node_modules/datatable/index.ts
Module build failed: Error: node_modules\datatable\index.ts is not part of the compilation output. Please check the other error messages for details.
    at AngularCompilerPlugin.getCompiledFile (node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:629:23)
    at plugin.done.then (node_modules\@ngtools\webpack\src\loader.js:467:39)
    at process._tickCallback (internal/process/next_tick.js:103:7)
 @ ./src/main/ui/app/app.module.ts 13:0-59
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
ERROR in ./node_modules/typeahead/index.ts
Module build failed: Error: node_modules\typeahead\index.ts is not part of the compilation output. Please check the other error messages for details.
    at AngularCompilerPlugin.getCompiledFile (\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:629:23)
    at plugin.done.then (node_modules\@ngtools\webpack\src\loader.js:467:39)
    at process._tickCallback (internal/process/next_tick.js:103:7)
 @ ./src/main/ui/app/app.module.ts 12:0-59
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

Does anyone have any suggestions on how to fix this?
Thank you.

Body:
I had a similar issue with angular-bootstrap-md\index.ts

how I could fix it:

Just put the index.ts file to the tsconfig.jsons include block ,
  see below:

{
  "compileOnSave": false,
  "compilerOptions": {
  "outDir": "./dist/out-tsc",
  "sourceMap": true,
  "declaration": false,
  "moduleResolution": "node",
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "target": "es5",
  "typeRoots": [
    "node_modules/@types"
  ],
  "lib": [
    "es2017",
    "dom"
  ]
},
"include": [
  "src/**/*",
  "node_modules/angular-bootstrap-md/index.ts"
  ]
 }

Source: https://github.com/angular/angular/issues/20091


问:
Add Overlay to Image in HTML EMail Compatible With Most Desktop and Web EMail Clients
Is there a way in 2017 to display either an image- or text-based overlay over the main image inside an HTML email, so that it is properly rendered by most of the current Desktop and Web email clients: Outlook 2007+, Thunderbird, Mobile Clients, GMail, Outlook.com, Yahoo Mail, etc.?

As an example, it could be a small play button rendering over the main image, that when clicked would take you to a video url.

答:
Yes, although it requires a lot of code since Outlook doesn't support CSS background-image, so we have to use VML in addition to CSS to get a background image displaying everywhere. backgrounds.cm is a good starting point but hasn't been updated in some time. Something like this is a good starting point to build on:

```<code><tr>
    <!-- Bulletproof Background Images c/o https://backgrounds.cm -->
    <td background="http://placehold.it/600x180/222222/666666" bgcolor="#222222" valign="middle" style="background-position: center center !important; background-size: cover !important;">
        <!--[if gte mso 9]>
        <v:image xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="border: 0; display: inline-block; width: 600px; height: 180px;" src="http://placehold.it/600x180/222222/666666" />
        <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="border: 0; display: inline-block; position: absolute; width: 600px; height: 180px;">
        <v:fill opacity="0%" color="#222222" />
        <![endif]-->
        <div>
            <!--[if mso]>
            <table role="presentation" border="0" cellspacing="0" cellpadding="0" align="center" width="600">
            <tr>
            <td align="center" valign="top" width="600">
            <![endif]-->
            <table role="presentation" border="0" cellpadding="0" cellspacing="0" align="center" width="100%">
                <tr>
                    <td valign="middle" style="padding: 20px; color: #ffffff;">
                        <img src="http://placehold.it/100" height="100" width="200" alt="">
                        <p style="margin: 0;">Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium lobortis rhoncus ut erat.</p>
                    </td>
                </tr>
            </table>
            <!--[if mso]>
            </td>
            </tr>
            </table>
            <![endif]-->
        </div>
        <!--[if gte mso 9]>
        </v:fill>
        </v:rect>
        </v:image>
        <![endif]-->
    </td>
</tr>
</code>```

Body:
Yes, although it requires a lot of code since Outlook doesn't support CSS background-image, so we have to use VML in addition to CSS to get a background image displaying everywhere. backgrounds.cm is a good starting point but hasn't been updated in some time. Something like this is a good starting point to build on:

<tr>
    <!-- Bulletproof Background Images c/o https://backgrounds.cm -->
    <td background="http://placehold.it/600x180/222222/666666" bgcolor="#222222" valign="middle" style="background-position: center center !important; background-size: cover !important;">
        <!--[if gte mso 9]>
        <v:image xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="border: 0; display: inline-block; width: 600px; height: 180px;" src="http://placehold.it/600x180/222222/666666" />
        <v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="border: 0; display: inline-block; position: absolute; width: 600px; height: 180px;">
        <v:fill opacity="0%" color="#222222" />
        <![endif]-->
        <div>
            <!--[if mso]>
            <table role="presentation" border="0" cellspacing="0" cellpadding="0" align="center" width="600">
            <tr>
            <td align="center" valign="top" width="600">
            <![endif]-->
            <table role="presentation" border="0" cellpadding="0" cellspacing="0" align="center" width="100%">
                <tr>
                    <td valign="middle" style="padding: 20px; color: #ffffff;">
                        <img src="http://placehold.it/100" height="100" width="200" alt="">
                        <p style="margin: 0;">Maecenas sed ante pellentesque, posuere leo id, eleifend dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent laoreet malesuada cursus. Maecenas scelerisque congue eros eu posuere. Praesent in felis ut velit pretium lobortis rhoncus ut&nbsp;erat.</p>
                    </td>
                </tr>
            </table>
            <!--[if mso]>
            </td>
            </tr>
            </table>
            <![endif]-->
        </div>
        <!--[if gte mso 9]>
        </v:fill>
        </v:rect>
        </v:image>
        <![endif]-->
    </td>
</tr>


问:
Issue with webgl coloring
I'll start off by saying that I'm new to webgl, only picked it up a few days ago for a computer graphics class and I'm having a problem with an application using dat.gui. What it's supposed to do is draw a rectangle with 2 clicks and color it with the color selected with the dat.gui controller, but the color that I get is a sort of a mix going from green, yellow, red and left bottom corner is black. If I comment the gl.enableVertexAttribArray(_color); line the rectangles are all black, so all I can think of is I'm not storing the color information correctly. I would very much appreciate it if someone could point me towards a solution or at least towards the problem. `

  <canvas width="570" height="570" id="my_Canvas"></canvas>

```

答:
You have to bind the proper vertex buffer before you call gl.vertexAttribPointer:

```<code>var coord = gl.getAttribLocation(shaderProgram, "coordinates");
var _color = gl.getAttribLocation(shaderProgram, "color");

.....

gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
gl.vertexAttribPointer(coord, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(coord);

gl.bindBuffer(gl.ARRAY_BUFFER, color_Buffer);
gl.vertexAttribPointer(_color, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(_color);
</code>```

Note, gl.vertexAttribPointer define an array of generic vertex attribute data refering to the currently bound ARRAY_BUFFER. See gl.bindBuffer.

Before you specify the vertex attributes for "coordinates" you bind vertex_buffer. But you don't bind color_Buffer befor you specify the vertex attributes for "color".

Because of that the vertex coordinate buffer is used for the color attributes too. his causes colorful lines and areas, because the colors are interpolated from point to point.

See the snippet:

    var canvas = document.getElementById('my_Canvas');
     gl = canvas.getContext('experimental-webgl');

    var vertCode=
    'attribute vec3 coordinates;' +
    'varying vec3 vColor;' +
    'attribute vec3 color;' +
    'void main(void){' +
    '   gl_Position=vec4(coordinates, 1.0);' +
    'vColor=color;' +
    '}';

    var vertShader=gl.createShader(gl.VERTEX_SHADER);
    gl.shaderSource(vertShader, vertCode);
    gl.compileShader(vertShader);

    var fragCode=
    'precision highp float;' +
    'varying vec3 vColor;' +
    'void main(void){' +
    '   gl_FragColor=vec4(vColor, 1.0);' +
    '}';

    var fragShader=gl.createShader(gl.FRAGMENT_SHADER);
    gl.shaderSource(fragShader, fragCode);
    gl.compileShader(fragShader);

    var shaderProgram=gl.createProgram();
    gl.attachShader(shaderProgram, vertShader);
    gl.attachShader(shaderProgram, fragShader);
    gl.linkProgram(shaderProgram);
    console.log(gl.getShaderInfoLog(vertShader));
    console.log(gl.getProgramInfoLog(shaderProgram));

    //var gui = new dat.GUI();
    var colore={
        colorv: [200,200,0]
    };

    //gui.addColor(colore, 'colorv');
    gl.clearColor(0.5, 0.5, 0.5, 1);
    gl.clear(gl.COLOR_BUFFER_BIT);

    var g_indices=[0,1,2,0,1,3];
    var colors=[];
    var p_counter=0; //this counter is used to detect if the point clicked is the 2nd point
    var g_counter=0; //this is a global counter, used as a multiplier for g_points
    var quad_g_counter;
    var dodeca_g_counter;
    var g_points = []; // the array for mousepress
    var indices=[];
    var vertex_buffer=gl.createBuffer();
    var Index_Buffer=gl.createBuffer();
    var color_Buffer=gl.createBuffer();

    function click(ev,gl,canvas){

        var x = ev.clientX;
        var y = ev.clientY;
        var rect = ev.target.getBoundingClientRect();

        x = ((x - rect.left) - canvas.height/2)/(canvas.height/2);
        y = (canvas.width/2 - (y - rect.top))/(canvas.width/2);

        //store the coords in g_points array

        g_points.push(x);g_points.push(y); g_points.push(0);

        // clear <canvas>
        gl.clear(gl.COLOR_BUFFER_BIT);
        p_counter+=1;

        if(p_counter==2){

            //g_points
            dodeca_g_counter=g_counter*12;
            g_points.push(g_points[dodeca_g_counter+3]);g_points.push(g_points[dodeca_g_counter+1]);g_points.push(0);
            g_points.push(g_points[dodeca_g_counter]);g_points.push(g_points[dodeca_g_counter+4]);g_points.push(0);

            //indices
            quad_g_counter=g_counter*4;
            indices.push(g_indices[0]+quad_g_counter);indices.push(g_indices[1]+quad_g_counter);
            indices.push(g_indices[2]+quad_g_counter);indices.push(g_indices[3]+quad_g_counter);
            indices.push(g_indices[4]+quad_g_counter);indices.push(g_indices[5]+quad_g_counter);

            //colors

            for(var i=0; i<4; i+=1){
                colors.push(colore.colorv[0]/255);colors.push(colore.colorv[1]/255);
                colors.push(colore.colorv[2]/255);
            }
            p_counter=0;
            g_counter+=1;
        }

            gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
            gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(g_points), gl.STATIC_DRAW);

            //gl.bindBuffer(gl.ARRAY_BUFFER, null);
            //gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);

            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, Index_Buffer);
            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);

            //gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
            gl.bindBuffer(gl.ARRAY_BUFFER, color_Buffer);
            gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);
            draw();
    }

    canvas.onmousedown = function(ev) {click(ev,gl,canvas);}

    function draw(){

        gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
        var coord=gl.getAttribLocation(shaderProgram, "coordinates");
        gl.vertexAttribPointer(coord, 3, gl.FLOAT, false, 0, 0);
        gl.enableVertexAttribArray(coord);

        gl.bindBuffer(gl.ARRAY_BUFFER, color_Buffer);
        var _color=gl.getAttribLocation(shaderProgram, "color");
        gl.vertexAttribPointer(_color, 3, gl.FLOAT, false, 0,0);
        gl.enableVertexAttribArray(_color);
        gl.useProgram(shaderProgram);

        gl.enable(gl.DEPTH_TEST);
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, Index_Buffer);
        gl.viewport(0, 0, canvas.width, canvas.height);
        gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0);
    }    ```
<pre class="snippet-code-html lang-html prettyprint-override"><code><canvas width="570" height="570" id="my_Canvas"></canvas></code>```

Title: Issue with webgl coloring

Body:
You have to bind the proper vertex buffer before you call gl.vertexAttribPointer:

var coord = gl.getAttribLocation(shaderProgram, "coordinates");
var _color = gl.getAttribLocation(shaderProgram, "color");

.....

gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
gl.vertexAttribPointer(coord, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(coord);

gl.bindBuffer(gl.ARRAY_BUFFER, color_Buffer);
gl.vertexAttribPointer(_color, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(_color);

Note, gl.vertexAttribPointer define an array of generic vertex attribute data refering to the currently bound ARRAY_BUFFER. See gl.bindBuffer.

Before you specify the vertex attributes for "coordinates" you bind vertex_buffer. But you don't bind color_Buffer befor you specify the vertex attributes for "color".

Because of that the vertex coordinate buffer is used for the color attributes too. his causes colorful lines and areas, because the colors are interpolated from point to point.

See the snippet:

    var canvas = document.getElementById('my_Canvas');
     gl = canvas.getContext('experimental-webgl');

    var vertCode=
    'attribute vec3 coordinates;' +
    'varying vec3 vColor;' +
    'attribute vec3 color;' +
    'void main(void){' +
    '   gl_Position=vec4(coordinates, 1.0);' +
    'vColor=color;' +
    '}';

    var vertShader=gl.createShader(gl.VERTEX_SHADER);
    gl.shaderSource(vertShader, vertCode);
    gl.compileShader(vertShader);

    var fragCode=
    'precision highp float;' +
    'varying vec3 vColor;' +
    'void main(void){' +
    '   gl_FragColor=vec4(vColor, 1.0);' +
    '}';

    var fragShader=gl.createShader(gl.FRAGMENT_SHADER);
    gl.shaderSource(fragShader, fragCode);
    gl.compileShader(fragShader);

    var shaderProgram=gl.createProgram();
    gl.attachShader(shaderProgram, vertShader);
    gl.attachShader(shaderProgram, fragShader);
    gl.linkProgram(shaderProgram);
    console.log(gl.getShaderInfoLog(vertShader));
    console.log(gl.getProgramInfoLog(shaderProgram));

    //var gui = new dat.GUI();
    var colore={
        colorv: [200,200,0]
    };

    //gui.addColor(colore, 'colorv');
    gl.clearColor(0.5, 0.5, 0.5, 1);
    gl.clear(gl.COLOR_BUFFER_BIT);

    var g_indices=[0,1,2,0,1,3];
    var colors=[];
    var p_counter=0; //this counter is used to detect if the point clicked is the 2nd point
    var g_counter=0; //this is a global counter, used as a multiplier for g_points
    var quad_g_counter;
    var dodeca_g_counter;
    var g_points = []; // the array for mousepress
    var indices=[];
    var vertex_buffer=gl.createBuffer();
    var Index_Buffer=gl.createBuffer();
    var color_Buffer=gl.createBuffer();

    function click(ev,gl,canvas){

        var x = ev.clientX;
        var y = ev.clientY;
        var rect = ev.target.getBoundingClientRect();

        x = ((x - rect.left) - canvas.height/2)/(canvas.height/2);
        y = (canvas.width/2 - (y - rect.top))/(canvas.width/2);

        //store the coords in g_points array

        g_points.push(x);g_points.push(y); g_points.push(0);

        // clear <canvas>
        gl.clear(gl.COLOR_BUFFER_BIT);
        p_counter+=1;

        if(p_counter==2){

            //g_points
            dodeca_g_counter=g_counter*12;
            g_points.push(g_points[dodeca_g_counter+3]);g_points.push(g_points[dodeca_g_counter+1]);g_points.push(0);
            g_points.push(g_points[dodeca_g_counter]);g_points.push(g_points[dodeca_g_counter+4]);g_points.push(0);

            //indices
            quad_g_counter=g_counter*4;
            indices.push(g_indices[0]+quad_g_counter);indices.push(g_indices[1]+quad_g_counter);
            indices.push(g_indices[2]+quad_g_counter);indices.push(g_indices[3]+quad_g_counter);
            indices.push(g_indices[4]+quad_g_counter);indices.push(g_indices[5]+quad_g_counter);

            //colors

            for(var i=0; i<4; i+=1){
                colors.push(colore.colorv[0]/255);colors.push(colore.colorv[1]/255);
                colors.push(colore.colorv[2]/255);
            }
            p_counter=0;
            g_counter+=1;
        }

            gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
            gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(g_points), gl.STATIC_DRAW);

            //gl.bindBuffer(gl.ARRAY_BUFFER, null);
            //gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);

            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, Index_Buffer);
            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);

            //gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
            gl.bindBuffer(gl.ARRAY_BUFFER, color_Buffer);
            gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(colors), gl.STATIC_DRAW);
            draw();
    }

    canvas.onmousedown = function(ev) {click(ev,gl,canvas);}

    function draw(){

        gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);
        var coord=gl.getAttribLocation(shaderProgram, "coordinates");
        gl.vertexAttribPointer(coord, 3, gl.FLOAT, false, 0, 0);
        gl.enableVertexAttribArray(coord);

        gl.bindBuffer(gl.ARRAY_BUFFER, color_Buffer);
        var _color=gl.getAttribLocation(shaderProgram, "color");
        gl.vertexAttribPointer(_color, 3, gl.FLOAT, false, 0,0);
        gl.enableVertexAttribArray(_color);
        gl.useProgram(shaderProgram);

        gl.enable(gl.DEPTH_TEST);
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, Index_Buffer);
        gl.viewport(0, 0, canvas.width, canvas.height);
        gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0);
    }

<canvas width="570" height="570" id="my_Canvas"></canvas>


问:
QFileDialog used as widget
My goal is: user can choose file (only *mp3) and after clicking twice on it it should play (so the QString to file should be send to play() function)
Firstly I started to work with QTreeView, but it has signal when the file is selected.

So I decided to create QFileDialog and used it as widget built-in into MainWindow.
The only problem that I have, that after double-click it disappears. It is possible to avoid it?

Should I work with some QDialog::finished() signal or, QDialog::done()?

答:
First, you can get a double-click signal from QTreeView; it's:

```<code>void doubleClicked( const QModelIndex & index );
</code>```

Second, if you really want to use the QFileDialog that way, first override closeEvent( QCloseEvent * event). Inside, if you want to close the dialog, do event->accept();, otherwise just do event->ignore();. Connect to QFileDialog::currentChanged( const QString & path ); to get the filename the user double-clicks. One last thing--be sure to create the QFileDialog on the heap (using new), not on the stack (a local), and call show() on it instead of exec().

Remember that you can supply it with a parent (this) and you won't need to delete it later.

Title: QFileDialog used as widget

Body:
First, you can get a double-click signal from QTreeView; it's:

void doubleClicked( const QModelIndex & index );

Second, if you really want to use the QFileDialog that way, first override closeEvent( QCloseEvent * event). Inside, if you want to close the dialog, do event->accept();, otherwise just do event->ignore();. Connect to QFileDialog::currentChanged( const QString & path ); to get the filename the user double-clicks. One last thing--be sure to create the QFileDialog on the heap (using new), not on the stack (a local), and call show() on it instead of exec().

Remember that you can supply it with a parent (this) and you won't need to delete it later.


问:
best way to detect if node touch the frame
Im building some game with SpriteKit that include balls as SKShapeNode. I create a class that define the balls and their properties (including SKPhysicsBody). the balls should run on the screen, and the frame is the screen border (by using edgeLoopFrom: self.frame). I also created a path node that is located at the top of the screen. now, I want to do that if some ball reach the top border of the frame so some function will execute.
I read some about it and i'm not sure what is the right way to do so, if by using contactBitMask or if there is another and better option.
If the right way is by contactBitMask - do I have to set a struct for the balls node or can I set it inside their class?
thanks!</p>

答:
If I'm getting this right, when a ball hits the path node that is located at the top half of the screen you want a function to be called.

First, I'm not sure if a path node is more efficient than a sprite node, in fact I have never really used path nodes, but here is what you can do.

Spritekit

check out the link above. What you need to do is implement the SKPhysicsContactDelegate. This will allow you to access the functions didBegin() and didEnd(). These functions are called when a contact is made within the physicsworld.

```<code>class YourClass: SKScene, SKPhysicsContactDelegate {
    func didBegin(_ contact: SKPhysicsContact) {
    }

    func didEnd(_ contact: SKPhysicsContact) {
    }
}
</code>```

In order for these functions to be called, you need to set the physicsworld's contactDelegate to the class that will handle the calls. This would be your scene and a good place to set this is the didMove() function.

```<code>class YourClass: SKScene, SKPhysicsContactDelegate {
    func didMove(to view: SKView) {
        physicsWorld.contactDelegate = self
    }
</code>```

Now when a contact happens that is detectable, your didBegin() will be called, and when the contact ends the didEnd() will be called.

Now we need to give our nodes some physicsbodies and we can set the different bitmasks on them in order to detect collisions/contacts. These are the 3 bitmasks we are concerned about:

```<code>categoryTestBitMask
collisionTestBitMask
contactTestBitMask
</code>```

categoryTestBitMask: You can give nodes of similar type a category, example "ball" could be the category. All your different ball objects could have this same category. I use the "noCollision" category for when I want to detect a contact, but I don't want a collision to happen. You are limited to 32 different categories though so don't go crazy with tons of different ones.

collisionTestBitMask: Give your "ball" a category that you want a collision to happen with. Ex: set the collisiontestmask for your "ball" to the category bitmask of "wall". A collision is when 2 objects will physically run into each other; so your ball will bounce off the walls.

contactTestBitMask: a Contact is when 2 nodes overlap. So instead of the ball bouncing off something, it would call the contact method for our delegate. Note that you can set both the collision and contact bit masks to the same thing.

Now how do we set these masks. I use a Struct so that I can assign names to the bitmasks and set these 3 different masks with code. Something like this:

```<code>struct Mask {
static var ball: UInt32 = 0b10 //2
static var wall: UInt32 = 0b100 //4
static var pathNode: UInt32 = 0b1000 //8
}
</code>```

now within code you can set the masks:

```<code>let ball = SKSpriteNode()
ball.name = "ball"
ball.physicsBody = SKPhysicsBody()
ball.physicsBody.categoryTestBitMask = Mask.ball
ball.physicsBody.collisionTestBitMask = Mask.wall
ball.physicsBody.contactTestBitMask = Mask.pathNode | Mask.wall

let pathNode = SKSpriteNode()
pathNode.name = "pathNode"
pathNode.physicsBody = SKPhysicsBody()
pathNode.physicsBody.categoryTestBitMask = Mask.pathNode
pathNode.physicsBody.collisionTestBitMask = 0
pathNode.physicsBody.contactTestBitMask = Mask.pathNode
</code>```

Lets look at what we are saying here. We create a ball object and we set its category to "ball", we say we want it to have collisions with "wall" objects and we want our contact delegate functions to trigger with "pathNode" objects OR "wall" objects. Our pathNode object will have no collisions, and will have contacts with the ball.

Basically the ball will bounce off the walls, and will pass through the pathNode. It will call the contact delegate functions didbegin() and didend() with both the pathNode and wall objects.

Not finished yet... So when the function is called, how do we handle this? When the didbegin or didend function is called, it has a parameter of "contact". this contact param has 2 bodies to work with and these are the bodies that contacted each other. There are multiple ways we can handle this, but I'll just show you a simple way for now.

```<code>func didBegin(_ contact: SKPhysicsContact) {
    if contact.bodyA!.node!.name == "ball" {
    // bodyA is our ball
        switch contact.bodyB!.node!.name {
        case "pathNode":
            thisIsMyBallHitPathNodeFunction()
        case "wall":
            thisIsMyBallHitWallFunction()
        default:
            break
        }
    }
    else if contact.bodyB!.node!.name == "ball" {
    // bodyB is our ball
        switch contact.bodyA!.node!.name {
        case "pathNode":
            thisIsMyBallHitPathNodeFunction()
        case "wall":
            thisIsMyBallHitWallFunction()
        default:
            break
        }

    }

}
</code>```

Update:
What we are doing here is figuring out the type of bodyA and bodyB. So it starts with bodyA, if bodyA is a "ball", then we know that bodyA is a "ball and bodyB is the thing the ball came in contact with. We then use a switch statement to figure out what bodyB is. Once we know what bodyB is, we call the function that we need to call for that specific contact between these 2 nodes.

Then you just put your code into those specified functions of what you want to do.

This could be a lot to take in at once, If you are new I would suggest trying this out and trying to get it to work. After, I would youTube some videos on how to do this. It is a good idea to see how different people handle the same thing and then you can decide for your self on how to do it. This might not be the most elegant way of handling the contacts, but it works well and with some practice it will become second nature, Good luck!

Body:
If I'm getting this right, when a ball hits the path node that is located at the top half of the screen you want a function to be called.

First, I'm not sure if a path node is more efficient than a sprite node, in fact I have never really used path nodes, but here is what you can do.

Spritekit

check out the link above. What you need to do is implement the SKPhysicsContactDelegate. This will allow you to access the functions didBegin() and didEnd(). These functions are called when a contact is made within the physicsworld.

class YourClass: SKScene, SKPhysicsContactDelegate {
    func didBegin(_ contact: SKPhysicsContact) {
    }

    func didEnd(_ contact: SKPhysicsContact) {
    }
}

In order for these functions to be called, you need to set the physicsworld's contactDelegate to the class that will handle the calls. This would be your scene and a good place to set this is the didMove() function.

class YourClass: SKScene, SKPhysicsContactDelegate {
    func didMove(to view: SKView) {
        physicsWorld.contactDelegate = self
    }

Now when a contact happens that is detectable, your didBegin() will be called, and when the contact ends the didEnd() will be called.

Now we need to give our nodes some physicsbodies and we can set the different bitmasks on them in order to detect collisions/contacts. These are the 3 bitmasks we are concerned about:

categoryTestBitMask
collisionTestBitMask
contactTestBitMask

categoryTestBitMask: You can give nodes of similar type a category, example "ball" could be the category. All your different ball objects could have this same category. I use the "noCollision" category for when I want to detect a contact, but I don't want a collision to happen. You are limited to 32 different categories though so don't go crazy with tons of different ones.

collisionTestBitMask: Give your "ball" a category that you want a collision to happen with. Ex: set the collisiontestmask for your "ball" to the category bitmask of "wall". A collision is when 2 objects will physically run into each other; so your ball will bounce off the walls.

contactTestBitMask: a Contact is when 2 nodes overlap. So instead of the ball bouncing off something, it would call the contact method for our delegate. Note that you can set both the collision and contact bit masks to the same thing.

Now how do we set these masks. I use a Struct so that I can assign names to the bitmasks and set these 3 different masks with code. Something like this:

struct Mask {
static var ball: UInt32 = 0b10 //2
static var wall: UInt32 = 0b100 //4
static var pathNode: UInt32 = 0b1000 //8
}

now within code you can set the masks:

let ball = SKSpriteNode()
ball.name = "ball"
ball.physicsBody = SKPhysicsBody()
ball.physicsBody.categoryTestBitMask = Mask.ball
ball.physicsBody.collisionTestBitMask = Mask.wall
ball.physicsBody.contactTestBitMask = Mask.pathNode | Mask.wall

let pathNode = SKSpriteNode()
pathNode.name = "pathNode"
pathNode.physicsBody = SKPhysicsBody()
pathNode.physicsBody.categoryTestBitMask = Mask.pathNode
pathNode.physicsBody.collisionTestBitMask = 0
pathNode.physicsBody.contactTestBitMask = Mask.pathNode

Lets look at what we are saying here. We create a ball object and we set its category to "ball", we say we want it to have collisions with "wall" objects and we want our contact delegate functions to trigger with "pathNode" objects OR "wall" objects. Our pathNode object will have no collisions, and will have contacts with the ball.

Basically the ball will bounce off the walls, and will pass through the pathNode. It will call the contact delegate functions didbegin() and didend() with both the pathNode and wall objects.

Not finished yet... So when the function is called, how do we handle this? When the didbegin or didend function is called, it has a parameter of "contact". this contact param has 2 bodies to work with and these are the bodies that contacted each other. There are multiple ways we can handle this, but I'll just show you a simple way for now.

func didBegin(_ contact: SKPhysicsContact) {
    if contact.bodyA!.node!.name == "ball" {
    // bodyA is our ball
        switch contact.bodyB!.node!.name {
        case "pathNode":
            thisIsMyBallHitPathNodeFunction()
        case "wall":
            thisIsMyBallHitWallFunction()
        default:
            break
        }
    }
    else if contact.bodyB!.node!.name == "ball" {
    // bodyB is our ball
        switch contact.bodyA!.node!.name {
        case "pathNode":
            thisIsMyBallHitPathNodeFunction()
        case "wall":
            thisIsMyBallHitWallFunction()
        default:
            break
        }

    }

}

Update:
What we are doing here is figuring out the type of bodyA and bodyB. So it starts with bodyA, if bodyA is a "ball", then we know that bodyA is a "ball and bodyB is the thing the ball came in contact with. We then use a switch statement to figure out what bodyB is. Once we know what bodyB is, we call the function that we need to call for that specific contact between these 2 nodes.

Then you just put your code into those specified functions of what you want to do.

This could be a lot to take in at once, If you are new I would suggest trying this out and trying to get it to work. After, I would youTube some videos on how to do this. It is a good idea to see how different people handle the same thing and then you can decide for your self on how to do it. This might not be the most elegant way of handling the contacts, but it works well and with some practice it will become second nature, Good luck!


问:
Why are CSS keyframe animations broken in Vue components with scoped styling?
I'm trying to implement a CSS typing indicator in Vue. Without Vue, it looks like this:

.typing-indicator {
  background-color: #E6E7ED;
  width: auto;
  border-radius: 50px;
  padding: 20px;
  display: table;
  margin: 0 auto;
  position: relative;
  -webkit-animation: 2s bulge infinite ease-out;
          animation: 2s bulge infinite ease-out;
}
.typing-indicator:before, .typing-indicator:after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: -2px;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background-color: #E6E7ED;
}
.typing-indicator:after {
  height: 10px;
  width: 10px;
  left: -10px;
  bottom: -10px;
}
.typing-indicator span {
  height: 15px;
  width: 15px;
  float: left;
  margin: 0 1px;
  background-color: #9E9EA1;
  display: block;
  border-radius: 50%;
  opacity: 0.4;
}
.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink infinite 0.3333s;
          animation: 1s blink infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink infinite 0.6666s;
          animation: 1s blink infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink infinite 0.9999s;
          animation: 1s blink infinite 0.9999s;
}

@-webkit-keyframes blink {
  50% {
    opacity: 1;
  }
}

@keyframes blink {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
html {
  display: table;
  height: 100%;
  width: 100%;
}

body {
  display: table-cell;
  vertical-align: middle;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="typing-indicator">
  <span></span>
  <span></span>
  <span></span>
</div></code>```

– source: http://jsfiddle.net/Arlina/gtttgo93/

The problem is that the animation does not work when adding the scoped attribute to the component's style definition (

答:
Problem

The problem is down to how the Webpack loader for Vue (vue-loader), incorrectly, parses animation names when adding IDs to scoped selectors and other identifiers. This is important because vue-loader's CSS scoping uses unique attributes added to elements to replicate the behaviour of CSS scoping. While your keyframe names get IDs appended, references to keyframes in animation rules in scoped styles do not.

Your CSS:

```<code>@-webkit-keyframes blink {
  50% {
    opacity: 1;
  }
}

@keyframes blink {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}

.typing-indicator {
  ...
  -webkit-animation: 2s bulge infinite ease-out;
          animation: 2s bulge infinite ease-out;
}

.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink infinite 0.3333s;
          animation: 1s blink infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink infinite 0.6666s;
          animation: 1s blink infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink infinite 0.9999s;
          animation: 1s blink infinite 0.9999s;
}
</code>```

Should get transformed to:

```<code>@-webkit-keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}

@keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}

.typing-indicator {
  ...
  -webkit-animation: 2s bulge-data-v-xxxxxxxx infinite ease-out;
          animation: 2s bulge-data-v-xxxxxxxx infinite ease-out;
}

.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink-data-v-xxxxxxxx infinite 0.3333s;
          animation: 1s blink-data-v-xxxxxxxx infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink-data-v-xxxxxxxx infinite 0.6666s;
          animation: 1s blink-data-v-xxxxxxxx infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink-data-v-xxxxxxxx infinite 0.9999s;
          animation: 1s blink-data-v-xxxxxxxx infinite 0.9999s;
}
</code>```

However it only get's transformed to:

```<code>@-webkit-keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}

@keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}

.typing-indicator {
  ...
  -webkit-animation: 2s bulge infinite ease-out;
          animation: 2s bulge infinite ease-out;
}

.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink infinite 0.3333s;
          animation: 1s blink infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink infinite 0.6666s;
          animation: 1s blink infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink infinite 0.9999s;
          animation: 1s blink infinite 0.9999s;
}
</code>```

Something to note: in the actual transformation, references to keyframe names in animation rules are missing the -data-v-xxxxxxxx at the end. This is the bug.

Currently (as of 47c3317) the animation name in shorthand animation rule declarations is identified by getting the first value out of splitting the animation rule by any whitespace character[1]. However the formal definition for the animation property states the animation name could appear anywhere within the rule definition.

<single-animation> = <time> || <single-timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state> || [ none | <keyframes-name> ]

– animation formal syntax[2]

Therefore, while your animation declarations are valid, vue-loader is not able to parse it.

Workaround

The current workaround for this is to move your animation names to the beginning of animation rule declarations. Your keyframe declarations do not need changing, they remain inside the scoped stylesheet. Your animation declarations should now look like this:

```<code>.typing-indicator {
  ...
  -webkit-animation: bulge 2s infinite ease-out;
          animation: bulge 2s infinite ease-out;
}
.typing-indicator span:nth-of-type(1) {
  -webkit-animation: blink 1s infinite 0.3333s;
          animation: blink 1s infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: blink 1s infinite 0.6666s;
          animation: blink 1s infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: blink 1s infinite 0.9999s;
          animation: blink 1s infinite 0.9999s;
}
</code>```

References

[1] vue-loader/lib/style-compiler/plugins/scope-id.js#L67 @ 47c3317

[2] Definition for animation in the Editor's Draft of W3C specification CSS Animations Level 1

Body:
I'm trying to implement a CSS typing indicator in Vue. Without Vue, it looks like this:

.typing-indicator {
  background-color: #E6E7ED;
  width: auto;
  border-radius: 50px;
  padding: 20px;
  display: table;
  margin: 0 auto;
  position: relative;
  -webkit-animation: 2s bulge infinite ease-out;
          animation: 2s bulge infinite ease-out;
}
.typing-indicator:before, .typing-indicator:after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: -2px;
  height: 20px;
  width: 20px;
  border-radius: 50%;
  background-color: #E6E7ED;
}
.typing-indicator:after {
  height: 10px;
  width: 10px;
  left: -10px;
  bottom: -10px;
}
.typing-indicator span {
  height: 15px;
  width: 15px;
  float: left;
  margin: 0 1px;
  background-color: #9E9EA1;
  display: block;
  border-radius: 50%;
  opacity: 0.4;
}
.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink infinite 0.3333s;
          animation: 1s blink infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink infinite 0.6666s;
          animation: 1s blink infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink infinite 0.9999s;
          animation: 1s blink infinite 0.9999s;
}

@-webkit-keyframes blink {
  50% {
    opacity: 1;
  }
}

@keyframes blink {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
html {
  display: table;
  height: 100%;
  width: 100%;
}

body {
  display: table-cell;
  vertical-align: middle;
}

– source: http://jsfiddle.net/Arlina/gtttgo93/

The problem is that the animation does not work when adding the scoped attribute to the component's style definition (

Body:
Problem

The problem is down to how the Webpack loader for Vue (vue-loader), incorrectly, parses animation names when adding IDs to scoped selectors and other identifiers. This is important because vue-loader's CSS scoping uses unique attributes added to elements to replicate the behaviour of CSS scoping. While your keyframe names get IDs appended, references to keyframes in animation rules in scoped styles do not.

Your CSS:

@-webkit-keyframes blink {
  50% {
    opacity: 1;
  }
}

@keyframes blink {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}

.typing-indicator {
  ...
  -webkit-animation: 2s bulge infinite ease-out;
          animation: 2s bulge infinite ease-out;
}

.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink infinite 0.3333s;
          animation: 1s blink infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink infinite 0.6666s;
          animation: 1s blink infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink infinite 0.9999s;
          animation: 1s blink infinite 0.9999s;
}

Should get transformed to:

@-webkit-keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}

@keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}

.typing-indicator {
  ...
  -webkit-animation: 2s bulge-data-v-xxxxxxxx infinite ease-out;
          animation: 2s bulge-data-v-xxxxxxxx infinite ease-out;
}

.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink-data-v-xxxxxxxx infinite 0.3333s;
          animation: 1s blink-data-v-xxxxxxxx infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink-data-v-xxxxxxxx infinite 0.6666s;
          animation: 1s blink-data-v-xxxxxxxx infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink-data-v-xxxxxxxx infinite 0.9999s;
          animation: 1s blink-data-v-xxxxxxxx infinite 0.9999s;
}

However it only get's transformed to:

@-webkit-keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}

@keyframes blink-data-v-xxxxxxxx {
  50% {
    opacity: 1;
  }
}
@-webkit-keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}
@keyframes bulge-data-v-xxxxxxxx {
  50% {
    -webkit-transform: scale(1.05);
            transform: scale(1.05);
  }
}

.typing-indicator {
  ...
  -webkit-animation: 2s bulge infinite ease-out;
          animation: 2s bulge infinite ease-out;
}

.typing-indicator span:nth-of-type(1) {
  -webkit-animation: 1s blink infinite 0.3333s;
          animation: 1s blink infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: 1s blink infinite 0.6666s;
          animation: 1s blink infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: 1s blink infinite 0.9999s;
          animation: 1s blink infinite 0.9999s;
}

Something to note: in the actual transformation, references to keyframe names in animation rules are missing the -data-v-xxxxxxxx at the end. This is the bug.

Currently (as of 47c3317) the animation name in shorthand animation rule declarations is identified by getting the first value out of splitting the animation rule by any whitespace character[1]. However the formal definition for the animation property states the animation name could appear anywhere within the rule definition.

<single-animation> = <time> || <single-timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state> || [ none | <keyframes-name> ]

– animation formal syntax[2]

Therefore, while your animation declarations are valid, vue-loader is not able to parse it.

Workaround

The current workaround for this is to move your animation names to the beginning of animation rule declarations. Your keyframe declarations do not need changing, they remain inside the scoped stylesheet. Your animation declarations should now look like this:

.typing-indicator {
  ...
  -webkit-animation: bulge 2s infinite ease-out;
          animation: bulge 2s infinite ease-out;
}
.typing-indicator span:nth-of-type(1) {
  -webkit-animation: blink 1s infinite 0.3333s;
          animation: blink 1s infinite 0.3333s;
}
.typing-indicator span:nth-of-type(2) {
  -webkit-animation: blink 1s infinite 0.6666s;
          animation: blink 1s infinite 0.6666s;
}
.typing-indicator span:nth-of-type(3) {
  -webkit-animation: blink 1s infinite 0.9999s;
          animation: blink 1s infinite 0.9999s;
}

References

[1] vue-loader/lib/style-compiler/plugins/scope-id.js#L67 @ 47c3317

[2] Definition for animation in the Editor's Draft of W3C specification CSS Animations Level 1


问:
Input field and button side by side in center
I have an input field and a button that I want to have horizontally and vertically centered (without transform) side by side in the middle. I can easily fix the centering part, but to place the input field and the button side by side has proven to be much harder. For whatever reason, the button is placed lower than the input field.

The HTML and CSS:

body {
  background: #000;
  text-align: center;
 }
.hd {
  font-size: 3.9rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  color: rgb(250, 250, 250);
  margin-bottom: 30px;
 }
.content {
  margin: 0;
  position: relative;
    margin-top: 20vh;
 }
.form-control, .btn {
  display: inline-block;
  padding: 10px 25px;
  font-size: 1rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  border-radius: 0;
  -webkit-appearance: none;
 }
.form-group {
  display: inline-block;
 }
.form-control {
  border: 0;
  float: left;
  width: 250px;
 }
*:focus {
  outline: none;
 }
.form-controlt:focus{
  outline: none;
 }
.btn {
  background-color: lightgreen;
  border: 0;
  background-color: #ff8e41;
  -o-transition: all .3s;
  transition: all .3s;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  font-style: normal;
  font-weight: 600;
  position: relative;
  border: 0;
  box-sizing: border-box;
  color: #fff;
  text-align: center;
  margin: 0 auto;
  -webkit-appearance: button;
  cursor: pointer;
 }
.btn::-moz-focus-inner {
  border: 0;
 }
.btn[type=submit]:active {
  background: #ed7a18;
  box-shadow: 0 1px 0 0 hsla(0,0%,100%,.27),inset 0 1px 0 0 #bc5f10;
 }
.btn[type=submit]:hover {
  background-color: #ffa353;
  -o-transition: all .3s;
  transition: all .3s;
 }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="content">

  <div class="hd">Text</div>

 <form action="8dy9s8hsd9.php" method="POST">

  <div id="name-group" class="form-group">
   <input type="text" class="form-control">
  </div>

  <button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>

 </form>
</div></code>```

答:
Change:

```<code><div id="name-group" class="form-group">
    <input type="text" class="form-control">
</div>

<button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
</code>```

To:

```<code><div id="name-group" class="form-group">
    <input type="text" class="form-control">

    <button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
</div>
</code>```

body {
  background: #000;
  text-align: center;
 }
.hd {
  font-size: 3.9rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  color: rgb(250, 250, 250);
  margin-bottom: 30px;
 }
.content {
  margin: 0;
  position: relative;
    margin-top: 20vh;
 }
.form-control, .btn {
  display: inline-block;
  padding: 10px 25px;
  font-size: 1rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  border-radius: 0;
  -webkit-appearance: none;
 }
.form-group {
  display: inline-block;
 }
.form-control {
  border: 0;
  float: left;
  width: 250px;
 }
*:focus {
  outline: none;
 }
.form-controlt:focus{
  outline: none;
 }
.btn {
  background-color: lightgreen;
  border: 0;
  background-color: #ff8e41;
  -o-transition: all .3s;
  transition: all .3s;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  font-style: normal;
  font-weight: 600;
  position: relative;
  border: 0;
  box-sizing: border-box;
  color: #fff;
  text-align: center;
  margin: 0 auto;
  -webkit-appearance: button;
  cursor: pointer;
 }
.btn::-moz-focus-inner {
  border: 0;
 }
.btn[type=submit]:active {
  background: #ed7a18;
  box-shadow: 0 1px 0 0 hsla(0,0%,100%,.27),inset 0 1px 0 0 #bc5f10;
 }
.btn[type=submit]:hover {
  background-color: #ffa353;
  -o-transition: all .3s;
  transition: all .3s;
 }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="content">

  <div class="hd">Text</div>

<form action="8dy9s8hsd9.php" method="POST">

 <div id="name-group" class="form-group">
  <input type="text" class="form-control">
     <button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
 </div>
</form>
</div></code>```

Body:
I have an input field and a button that I want to have horizontally and vertically centered (without transform) side by side in the middle. I can easily fix the centering part, but to place the input field and the button side by side has proven to be much harder. For whatever reason, the button is placed lower than the input field.

The HTML and CSS:

body {
  background: #000;
  text-align: center;
 }
.hd {
  font-size: 3.9rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  color: rgb(250, 250, 250);
  margin-bottom: 30px;
 }
.content {
  margin: 0;
  position: relative;
    margin-top: 20vh;
 }
.form-control, .btn {
  display: inline-block;
  padding: 10px 25px;
  font-size: 1rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  border-radius: 0;
  -webkit-appearance: none;
 }
.form-group {
  display: inline-block;
 }
.form-control {
  border: 0;
  float: left;
  width: 250px;
 }
*:focus {
  outline: none;
 }
.form-controlt:focus{
  outline: none;
 }
.btn {
  background-color: lightgreen;
  border: 0;
  background-color: #ff8e41;
  -o-transition: all .3s;
  transition: all .3s;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  font-style: normal;
  font-weight: 600;
  position: relative;
  border: 0;
  box-sizing: border-box;
  color: #fff;
  text-align: center;
  margin: 0 auto;
  -webkit-appearance: button;
  cursor: pointer;
 }
.btn::-moz-focus-inner {
  border: 0;
 }
.btn[type=submit]:active {
  background: #ed7a18;
  box-shadow: 0 1px 0 0 hsla(0,0%,100%,.27),inset 0 1px 0 0 #bc5f10;
 }
.btn[type=submit]:hover {
  background-color: #ffa353;
  -o-transition: all .3s;
  transition: all .3s;
 }

Text

 <form action="8dy9s8hsd9.php" method="POST">

   <input type="text" class="form-control">

  <button type="submit" class="btn btn-success">Submit</button>

 </form>

Body:
Change:

<div id="name-group" class="form-group">
    <input type="text" class="form-control">
</div>

<button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>

To:

<div id="name-group" class="form-group">
    <input type="text" class="form-control">

    <button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
</div>

body {
  background: #000;
  text-align: center;
 }
.hd {
  font-size: 3.9rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  color: rgb(250, 250, 250);
  margin-bottom: 30px;
 }
.content {
  margin: 0;
  position: relative;
    margin-top: 20vh;
 }
.form-control, .btn {
  display: inline-block;
  padding: 10px 25px;
  font-size: 1rem;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  border-radius: 0;
  -webkit-appearance: none;
 }
.form-group {
  display: inline-block;
 }
.form-control {
  border: 0;
  float: left;
  width: 250px;
 }
*:focus {
  outline: none;
 }
.form-controlt:focus{
  outline: none;
 }
.btn {
  background-color: lightgreen;
  border: 0;
  background-color: #ff8e41;
  -o-transition: all .3s;
  transition: all .3s;
  font-family: Open Sans,Segoe UI,Arial,Verdana,Tahoma,sans-serif;
  font-style: normal;
  font-weight: 600;
  position: relative;
  border: 0;
  box-sizing: border-box;
  color: #fff;
  text-align: center;
  margin: 0 auto;
  -webkit-appearance: button;
  cursor: pointer;
 }
.btn::-moz-focus-inner {
  border: 0;
 }
.btn[type=submit]:active {
  background: #ed7a18;
  box-shadow: 0 1px 0 0 hsla(0,0%,100%,.27),inset 0 1px 0 0 #bc5f10;
 }
.btn[type=submit]:hover {
  background-color: #ffa353;
  -o-transition: all .3s;
  transition: all .3s;
 }

<div class="content">

  <div class="hd">Text</div>

<form action="8dy9s8hsd9.php" method="POST">

 <div id="name-group" class="form-group">
  <input type="text" class="form-control">
     <button type="submit" class="btn btn-success">Submit<span class="fa fa-arrow-right"></span></button>
 </div>
</form>
</div>


问:
In tornado, is threadpoolexecutor thread-safe?
In tornado, we can use ThreadPoolExecutor to execute calls asynchronously, but the ThreadPoolExecutor or @run_on_executor is thread-safe?
  If the answer is 'no', how to solve the problem of resource sharing?</p>

答:
Is ThreadPoolExecutor thread safe?

ThreadPoolExecutor is safe  as long as your code is safe. All it does is it runs your code in multiple threads. Ultimately, it's all up to you to make your code thread-safe.

How to solve the problem of resource sharing?

By not sharing the resource. Anytime you need to do anything with the resource you call the main thread and do it there.

In Tornado, you can submit control back to the main thread using ioloop.IOLoop.add_callback. So, you can run your code in ThreadPoolExecutor, but anytime you want to do anything with a resource, you submit control back to the main thread.

Example:

x = 1

def print_x():
    global x

    if x == 1:
        print x
        x += 1
```

<p>As you can see, the above code is not thread safe because every thread can modify <code>x</code>. </p>

<p>To run it in a thread-safe manner, you'll have to perform the condition check and modify x in the main thread. That is, you'll have to run the <code>print_x</code> function only in the main thread, like this:</p>

<pre class="lang-python prettyprint-override"><code>x = 1

def print_x():
    # run it only in the main thread for thread-safety
    global x

    if x == 1:
        print x
        x += 1

def call_print_x():
    # this can be run in any thread
    # it asks the main thread to run `print_x`

    loop = ioloop.IOLoop.current()
    loop.add_callback(print_x) # submit control to main thread
</code>```

Body:
Is ThreadPoolExecutor thread safe?

ThreadPoolExecutor is safe  as long as your code is safe. All it does is it runs your code in multiple threads. Ultimately, it's all up to you to make your code thread-safe.

How to solve the problem of resource sharing?

By not sharing the resource. Anytime you need to do anything with the resource you call the main thread and do it there.

In Tornado, you can submit control back to the main thread using ioloop.IOLoop.add_callback. So, you can run your code in ThreadPoolExecutor, but anytime you want to do anything with a resource, you submit control back to the main thread.

Example:

x = 1

def print_x():
    global x

    if x == 1:
        print x
        x += 1

As you can see, the above code is not thread safe because every thread can modify x.

To run it in a thread-safe manner, you'll have to perform the condition check and modify x in the main thread. That is, you'll have to run the print_x function only in the main thread, like this:

x = 1

def print_x():
    # run it only in the main thread for thread-safety
    global x

    if x == 1:
        print x
        x += 1

def call_print_x():
    # this can be run in any thread
    # it asks the main thread to run `print_x`

    loop = ioloop.IOLoop.current()
    loop.add_callback(print_x) # submit control to main thread


问:
http POST in angular 2 client not working while http GET is working
I am trying to do an http POST request on angular 2 client (asp.net core 2.0 api server).

At first there was an 415 error (Unsupported Media).

When I add an header there is a response to preflight request doesn't pass access control check: No 'Access-Control-Origin' header is present on the requested resource error.

Http GET in the same service is working perfectly(without headers).

import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';

export class MyService {

  constructor(private http: Http) {}

    // This is working
    getStudents(): Observable <string[]>{
      return this.http.get('https://localhost:44753/api/students', {withCredentials:true})
        .map((res:Response)=> res.Json());
    }

    // Return 415
    getStudent(name): Observable <string[]>{
    let data = {
      "name": name
    }
      return this.http.get('https://localhost:44753/api/students', JSON.Stringify(data),          {withCredentials:true})
        .map((res:Response)=> res.Json());
    }

    // Return 401
     getStudent2(name): Observable <string[]>{
      let data = {
        "name": name
      }

      let headers = new Header();
      headers.append('Content-Type', 'application/json);
      headers.append('Access-Control-Allow-Origin', '*');

      let options = new RequestOptions({ headers:headers , withCredentials:true });

        return this.http.get('https://localhost:44753/api/students', JSON.Stringify(data),          options)
          .map((res:Response)=> res.Json());
     }

 }```

Can someone help me solve this?

答:
You can use SearchParams instead of headers in get call

```<code>    public getStudent = (name: string): Observable<string[]> => {

    let params: URLSearchParams = new URLSearchParams();
    params.set('name', name);
    this.options.params = params;

    return this.http.get('https://localhost:44753/api/students', this.options)
        .map(
        data => data.json()
        );
};
</code>```

also double check if you are expecting single string instead of string[]

and decorate by  [HttpGet("{name}")] your WebApi method

```<code>[HttpGet("{name}")]
public List<string> Students (string name){.....
</code>```

Body:
I am trying to do an http POST request on angular 2 client (asp.net core 2.0 api server).

At first there was an 415 error (Unsupported Media).

When I add an header there is a response to preflight request doesn't pass access control check: No 'Access-Control-Origin' header is present on the requested resource error.

Http GET in the same service is working perfectly(without headers).

import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';

export class MyService {

  constructor(private http: Http) {}

    // This is working
    getStudents(): Observable <string[]>{
      return this.http.get('https://localhost:44753/api/students', {withCredentials:true})
        .map((res:Response)=> res.Json());
    }

    // Return 415
    getStudent(name): Observable <string[]>{
    let data = {
      "name": name
    }
      return this.http.get('https://localhost:44753/api/students', JSON.Stringify(data),          {withCredentials:true})
        .map((res:Response)=> res.Json());
    }

    // Return 401
     getStudent2(name): Observable <string[]>{
      let data = {
        "name": name
      }

      let headers = new Header();
      headers.append('Content-Type', 'application/json);
      headers.append('Access-Control-Allow-Origin', '*');

      let options = new RequestOptions({ headers:headers , withCredentials:true });

        return this.http.get('https://localhost:44753/api/students', JSON.Stringify(data),          options)
          .map((res:Response)=> res.Json());
     }

 }

Can someone help me solve this?

Body:
You can use SearchParams instead of headers in get call

    public getStudent = (name: string): Observable<string[]> => {

    let params: URLSearchParams = new URLSearchParams();
    params.set('name', name);
    this.options.params = params;

    return this.http.get('https://localhost:44753/api/students', this.options)
        .map(
        data => data.json()
        );
};

also double check if you are expecting single string instead of string[]

and decorate by  [HttpGet("{name}")] your WebApi method

[HttpGet("{name}")]
public List<string> Students (string name){.....