星期五, 2月 06, 2015

[Angular] ng-src造成的infinite loop

目前在介面上顯示圖片列表時,因為圖片的網址加了random的參數來解決cache的議題,
但會產生infinite loop的error,打開console可以看到。
找到了Stackoverflow以下解譯這個的原因。

http://stackoverflow.com/questions/17222526/angular-js-in-ng-src-causes-infinite-loop
Well I think the problem is the getRandom function returning a different value every time it's called. Here's what happens:
  1. Angular call your function
  2. Gets the value
  3. See's it's different from the previous value
  4. Marks the cycle as dirty
  5. After the cycle is finished it re-runs the cycle thus getting a new value ...
The idea would be to have getRandom give discreet values over a period of time. For example only give a new value every 1, 10, 30 sec whatever you see fit.
This advice applies to many things, actually. Angular provides no guarantees about how many times it will call your functions that are found in bindings. So you need to make them fast and also you need to make sure that for the same input they return the same output(most times, though in this case it might be justified).
Also consider exactly when/how the image might change and if the actual changes can be triggered by something else consider only creating a new result value for getRandom only when the actual changes are triggered(ex: user uploads a new profile image, a timer executes, etc)
UPDATE: Can't replicate it in plunker using Chrome

解決的方法可以利用一個timer來透過記錄上一次變更的時間差來避免一直檢查的問題。




$scope.lastMillis = new Date().getTime();
     $scope.getRandom=function(){
         var curMillis = new Date().getTime();
         if (curMillis-$scope.lastMillis>5000) {
             $scope.lastMillis = curMillis;
         }
         return $scope.lastMillis;
     };

星期三, 2月 04, 2015

[Andorid] Mac版Eclipse ADT 安裝擷圖

骨灰級Eclipse安裝ADT圖文擷取記錄 :D

安裝ADT外掛,輸入網址

[CSS] IE8 顯示背景圖的icon的解決方法

遇到IE8的背景圖跑不出來的問題,另外ie8也看不懂 background-position 與 background-size

「background-size」是 CSS3 才有的進階語法,ie9後才有支援
.nav-icon-devicemgmt{
    background: url('../images/icons/nav-icon-devicemgmt.png') no-repeat left  ;
}

/*IE8可跑*/
.nav-icon-devicemgmt{  
    background-size: 32px 32px;
    background-image:url('../images/icons/nav-icon-devicemgmt.png') ;
    background-repeat:  no-repeat;
    background-position:  left ;
    background-position-x: 5px;
}

星期二, 2月 03, 2015

[jQuery API] IE8 隱藏column後表格寬度異常解決方法

昨天遇到ie8在表格的column隱藏時,表格的寬度未自動變動的問題。
慘況如下圖記念擷圖


找到這個作者的解法,透過變動display的屬性成inline-talbe,再透過setTimeout再把dispaly重設,表格的寬度就會正常了。


[CSS] IE8 border無法正常顯示

記錄一下處理ie8有關border無法正常顯示議題

/*.tblList tr td{
     position: relative;fix ie8 border issue
}
*/
先前的版本為了讓border的寬度能在ie8顯示,於是加了position:relative,但卻造成了後面版本的border卻顯示不出來

星期三, 1月 28, 2015

[Android] Android Studio 安裝記錄

最近要開始把玩Andorid,由於新手入門大家都建議不用完Eclipse ADTXD,
直接換Android Studio開發可能對長遠比較好,加上AS的功能與性能似乎幹爆Eclipse。
以下是安裝過程中炸掉的處理方法

安裝步驟

Step1: 遇到安裝JDK前會爆炸的話,請先下載這個補丁XD
http://support.apple.com/kb/DL1572?viewlocale=zh_TW&locale=en_US
Step2: 安裝JDK
Step3: 指定AS要用的JDK路徑,之後就一直下一步Next

網路上額外找的相關JDK的安裝路徑
For different types of JDKs or installations, you will have different paths.
On Mac OS X Mavericks, the path I found as following:
1) Built-in JRE default:
 /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
2) JDKs downloaded from Apple:
 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
3) JDKs downloaded from Oracle:
/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home

Step4: 開始享用

參考

http://blog.ccc99.tw/2014/10/os-x-1010-java.html

星期二, 1月 20, 2015

[Java] Unable to load class for JSP 炸掉筆記

20150204更新:
最後發現有重覆的jar甘擾造成慘劇!!

  • jasper-compiler-5.5.23.jar
  • jasper-runtime-5.5.23.jar
  • jsp-2.1-6.1.14.jar
  • jsp-api-2.1-6.1.14.jar



好死不死遇到Unable to load class for JSP ,
手記這個bug的處理情況, 問了google大神也一堆人遇到
但沒統一的解法,有的人是用到的jar有衝突還是缺之類的,還是classpath跑掉blabla
目前的狀況整個IDE新舊專案的JSP都無法編譯。
索性就用重灌ide的方法,結果執行的時候也爆了。
原來一灌的時候,忘了設Tomcat的VM Options(會導致libs無法載入太多而炸掉)
接著就能跑了....


炸掉的error



星期一, 1月 19, 2015

[NetBeans] 設定Utf-8編碼

預設的netbeans好像沒有gui設定utf-8編碼開啟檔案,可以透過修改設定檔的方式來解決

步驟:


1. 打開設定檔:
C:\Program Files (x86)\NetBeans 7.2.1\etc\netbeans.conf

2. 找到netbeans_default_options參數

3. 加入-J-Dfile.encoding=UTF-8


星期二, 1月 06, 2015

[NetBeans] 自動刷新專案目錄結構

記錄一下刷新netbeans專案目錄的ide操作

手動掃描變動

"Source" > "Scan for External Changes"

自動掃描變動

ide預設好像是開啟的:d


[NetBeans] Project Group功能筆記

如果有多個專案版本要同時在netbeans運行可以使用Project Group這個功能來切換不同的project,記錄有關於這功能的事項:D

設定檔路徑

找不到怎麼砍掉舊有的project group可以到以下路徑

%USER_HOME%\AppData\Roaming\NetBeans\<版本號>\config\Preferences\org\netbeans\module‌​s\projectui\groups

裡面有產生java的properties檔案來記錄相關資訊,檔名為 .properties

星期日, 12月 21, 2014

[jQuery Plugin] required depends 讓驗證欄位基於其他特地條件成立

如果你使用jquery validator要讓required規則依特地條件成立才驗證的話, 可以使用呼叫的depends方法,並自訂規則:D
$('#ProspectDtlFrm').validate({ 
    rules: {
        prsptEmail: {
            required: {
                depends: function(element) {
                    return ($('#prsptHomePhone').val() == '' && 
                            $('#prsptBusinessPhone').val() == '' && 
                            $('#prsptMobilePhone').val() == '');
                }
            }
        }    
    }, 
    messages: { 
        prsptEmail: 'Please enter your first name'
    } 
});

Reference
jquery validate depends rule

星期四, 12月 18, 2014

星期二, 12月 09, 2014

[jQuery Mobile] 設定select menu的初始化

想要指定select menu的初始化的話只要設定val就好了,但要記得refresh一下

範例:

  $('#frmAnalytics_ReportGroup').val('avg').selectmenu('refresh');

星期四, 12月 04, 2014

[jquery plugin] jquery validator 驗證多個選取盒checkbox

常用的需求,怕忘記直接寫個範例記一下。
以下範例介紹如何透過jquery validator來驗證多個checkboxes,
可以透過minlength參數來指定選取數量

HTML

欲代理區域:
                        <input type="checkbox" id="north" name="area" value="north" /> 北部
                        <input type="checkbox" id="central" name="area" value="central" /> 中部
                        <input type="checkbox" id="south" name="area" value="south" /> 南部
                        <input type="checkbox" id="east" name="area" value="east" /> 東部


JS範例

$validatedContact
   = $("#contactForm").validate({
    rules: {

     //共同 checkbox
     area: {
      required: true
      ,minlength: 2
     }
},
messages:{
area: {
      required: "區域未選取"
      ,minlength: "至少選取二個區域"
     }
},
 submitHandler: function(form) {
}
});


結果



[jQuery plugin] 移除已初始化過的jquery validator

今天有一個頁面需求,需求在切換不同type的時候,變更不同的form的顯示的欄位, 為了方便就是重設jquery validator,可以透過以下範例重設form的validator

範例

$("#contactForm").data("validator", null);
  $("#contactForm").unbind("validate");
  $("#contactForm").removeData("validator")
  $("#contactForm").unbind("submit");//必需移除submit的行為,不然會多重綁定

星期三, 12月 03, 2014

[Javascript] Timer議題: setTimeout 與 setInterval的筆記

最近用timer來實作dashboard相關的機制,順便查一查筆記一下:d

字面上說明

Timeout  ==>逾時
Interval  ==>間隔


定義:

Javascript的計時功能提供了setTimeout與setInterval這兩種用法,執行後會取得一個Timer ID。
要取消計時可以用的分別是clearTimeout()和clearInterval(),然後把執行後取得的Timer ID殺掉即可

兩者差別:


setTimeout()只做一次;setInterval()會不停的的調用函數。



運作原因:

由於javascript是只有單一執行緒,因此只是告訴Js在某一段時間後,再插入執行你指定的函式








星期二, 11月 18, 2014

[PHP] 西元日期轉中文年月日

如果有需要將西元日期轉換的話,可以不用拆解字串的方式。
可參考內建的date函數即可

echo date('Y年n月d日',strtotime('2014-11-18')); 

其他你感興趣的文章

Related Posts with Thumbnails