*.js
{ //挑選印表機
xtype: "fieldcontainer", fieldLabel: "印表機", labelWidth: 60, layout: "hbox", flex: 15,
items: [
{
xtype: "combobox", id: "sub_PRINTER", name: "sub_PRINTER", width:250, padding: "0 4 0 0",
store: store_PRNLIST,
emptyText: "--請選擇--", displayField: "Name", valueField: "Value",
queryMode: "local"
},
]
}, // end of 挑選印表機
xtype: "fieldcontainer", fieldLabel: "印表機", labelWidth: 60, layout: "hbox", flex: 15,
{
xtype: "combobox", id: "sub_PRINTER", name: "sub_PRINTER", width:250, padding: "0 4 0 0",
emptyText: "--請選擇--", displayField: "Name", valueField: "Value",
queryMode: "local"
},
]
}, // end of 挑選印表機
var np = {};
Ext.Ajax.request({
method: "POST",
url: '../../api/V120502API/Get_PRNLIST',
params: np,
async: false,
success: function (response, opts) {
console.log("0 response=", response);
console.log("0 response.responseText=", response.responseText);
var Tmp_Obj = Ext.decode(response.responseText);
//Ext.decode Array of Object 也可解碼 , Tmp_Obj : Array [{},{},..]
var Tmp_Name, Tmp_Value;
var cur_rec = {};
for (i = 0; i <Tmp_Obj.length; i++)
{
Tmp_Name = Tmp_Obj[i]["Key"];
Tmp_Value = Tmp_Obj[i]["Value"];
cur_rec = { Name: Tmp_Name, Value: Tmp_Value };
//cur_rec = { Name: Tmp_Obj[i]["Key"], Value: Tmp_Obj[i]["Value"] };
console.log("6 cur_rec= ", cur_rec);
store_PRNLIST.add(cur_rec);
}
//不可再 store_PRNLIST.load(); --> 會載入原始的 data , 後來新增item, 不會顯示
2>*.cs c# 呼叫 get_PRNLIST() 取得 主機端的 印表機選項
[HttpPost]
public HttpResponseMessage get_PRNLIST()
{
String Tmp_PRNNM;
String Tmp_RtnStr = "";
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
{
Tmp_PRNNM = PrinterSettings.InstalledPrinters[i];
PRNLIST.Add(Tmp_PRNNM, i.ToString());
Tmp_RtnStr = Tmp_RtnStr
+ "{Key:" + myfunc.AA(Tmp_PRNNM) + ",Value:" + i.ToString() + "},";
}
if (Tmp_RtnStr.Length > 0)
{
Tmp_RtnStr=Tmp_RtnStr.Substring(0, Tmp_RtnStr.Length-1);
Tmp_RtnStr = "[" + Tmp_RtnStr + "]";
};
var response = this.Request.CreateResponse();
response.Content = new StringContent(Tmp_RtnStr); // 回應內容
return response;
}
沒有留言:
張貼留言