2017年6月29日 星期四

使用 ng-repeat 時綁定 ng-model 注意事項

ng-repeat 使用自己的 scope,無法直接綁定原本 scope 的變數,前面需要加上"$parent."

 

2017年6月23日 星期五

欄位防呆檢查機制

以必要欄位為例

html
====
<form novalidate name="form1">
<select required name="帳戶編號" class='form-control' ng-model='selectData["帳戶編號"]' ng-options='a.value as a.text for a in accounts'><option value='' disabled>請選擇</option></select><span style='color:red' ng-show="form1['帳戶編號'].$error.required">*</span>
</form>

javascript
====
if ($scope.form1.$error.required) {
                toaster.error("必要欄位輸入不完整!!");
                return;
}

2017年6月19日 星期一

複製文字到剪貼簿

var currentFocus = document.activeElement;
var textArea = document.createElement("textarea");
textArea.value = "123";
document.body.appendChild(textArea);
textArea.select();
document.execCommand("copy");
document.body.removeChild(textArea);
if (currentFocus) currentFocus.focus();

jquery
====
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();

2017年6月15日 星期四

等待非同步執行完畢

寫法1
var deferred = $q.defer();
var promise = deferred.promise;
promise.then(function () {   
...
}).then(function () {
...
});
deferred.resolve();

寫法2
$q.all([$scope.refreshSelectData()]).finally(function () {
                    ...
                });

PS. 若呼叫 $http.post 則寫成return $http.post 否則還是不會等待

2017年6月7日 星期三

使用 UNC 方式存取資料夾

先下載此檔案 UNCAccessWithCredentials.cs

使用方式
const string path = @"\\172.16.1.1\aaa";
 using (UNCAccessWithCredentials unc = new UNCAccessWithCredentials())
            {
                unc.NetUseWithCredentials(path, 帳號, 網域, 密碼);
                var files = Directory.GetFiles(path).OrderBy(a => new FileInfo(a).CreationTime);
...

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...