2014-10-07 57 views
0

因此,我正在開發一個微軟的Lightswitch應用程序在C#中使用Visual Studio 2013,我需要一個動態的用戶界面。微軟Lightswitch使用C#創建動態用戶界面,jQuery的移動和JavaScript

基本上在數據庫中我有一個Person表,一個技能表和一個PersonSkills表,它們將兩者聯繫在一起(一個人可以有多種技能,每種技能都有技能級別。自動取出並完成)。

How it looks currently

現在AddSkill頁面上,我需要能夠添加,因爲我想盡可能多的技能,而不必一遍遍打開相同AddSkill彈出。我目前的做法是(使用谷歌瀏覽器)右鍵單擊+按鈕搜索技能並選擇檢查元素,以查看該按鈕的CSS代碼(因爲它是一個css/jquery移動元素)。

這給了我該技能框和級別框的CSS代碼,並且每當技能發生變化時使用lightswitch的postRender方法和.change jquery方法,我將其他技能和級別框的代碼添加到組件。

Inspect element

myapp.AddEditPersonSkill.left_postRender = function (element, contentItem) { 
// Write code here. 
var context = $(element); 

//Sorry that its all in one line and terrible... 

context.change(function() { 
    context.append('<div class="msls-first-column msls-presenter msls-ctl-rows-layout msls-vauto msls-hstretch msls-presenter-content msls-font-style-normal msls-hscroll msls-label-host msls-rows-layout" style="min-width: 200px; max-width: 400px; width: 229px;"><div class="msls-clear msls-first-row msls-presenter msls-ctl-details-modal-picker msls-vauto msls-hstretch msls-leaf"><div class="msls-label msls-label-align-top msls-clear msls-vauto"><label>Skill</label></div><div class="msls-clear msls-presenter-content msls-font-style-normal msls-vauto msls-hscroll"><div class="id-container"><form class="ui-listview-filter ui-bar-a ui-listview-filter-inset" role="search"><div class="ui-input-search ui-shadow-inset ui-btn-corner-all ui-btn-shadow ui-icon-searchfield ui-body-a ui-mini"><input placeholder="Search" data-type="search" class="ui-input-text ui-body-a"><a href="#" class="ui-input-clear ui-btn ui-btn-up-a ui-shadow ui-btn-corner-all ui-fullsize ui-btn-icon-notext ui-input-clear-hidden" title="clear text" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-icon="delete" data-iconpos="notext" data-theme="a" data-mini="false"><span class="ui-btn-inner"><span class="ui-btn-text">clear text</span><span class="ui-icon ui-icon-delete ui-icon-shadow">&nbsp;</span></span></a></div></form><ul class="id-auto-complete-element ui-listview ui-listview-inset ui-corner-all ui-shadow" data-role="listview" data-inset="true" data-filter="true" data-filter-theme="a" data-filter-placeholder="Search"></ul><a class="id-modal-button msls-has-search msls-large-icon ui-btn ui-btn-up-a ui-shadow ui-btn-corner-all ui-mini ui-btn-icon-notext" tabindex="0" data-role="button" data-icon="msls-add" data-mini="true" data-iconpos="notext" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="a" title=""><span class="ui-btn-inner"><span class="ui-btn-text"></span><span class="ui-icon ui-icon-msls-add ui-icon-shadow">&nbsp;</span></span></a></div><div class="id-auto-complete-dropdown"></div></div></div><div class="msls-clear msls-last-row msls-presenter msls-ctl-text-box msls-vauto msls-hstretch msls-leaf msls-redraw"><div class="msls-label msls-label-align-top msls-clear msls-vauto"><label for="b8bfe3adf-Level" class="ui-input-text">Level</label></div><div class="msls-clear msls-presenter-content msls-font-style-normal msls-vauto msls-hscroll"><div class="ui-input-text ui-shadow-inset ui-corner-all ui-btn-shadow ui-body-a ui-mini"><input type="text" class="id-element ui-input-text ui-body-a" data-mini="true" maxlength="255" id="b8bfe3adf-Level"></div></div></div><div class="msls-clear"></div></div>'); 

}); 

};

How it works currently

這就是所有罰款和良好的 - 但是,現在的問題是:新的技能框(剛加入到屏幕)沒有工作按鈕 - CSS/jQuery Mobile的按鈕不執行任何操作。第一個仍然正常工作,但新的一個壞了。

有沒有比我所做的更好的方式做到這一點?有沒有內置的lightswitch方式來做到這一點?

編輯:所以它看起來像jQuery的按鍵事件是JavaScript文件中的其他地方,而不是按鈕聲明本身內:

http://demos.jquerymobile.com/1.2.1/docs/buttons/buttons-events.html

這意味着即使我創造了「看起來和感覺'按鈕,他們實際上沒有做任何事情。我必須找出按鈕調用的方法,然後使用.bind jquery方法將新按鈕綁定到相同的方法。

+0

你能澄清,如果已經存在的技術記錄,你想要的是從人的屏幕聯想到現有的技能(創建新PersonSkill記錄)不開放每次都有PersonSkill屏幕? – 2014-10-07 15:31:47

+0

是的,這是絕對正確的。我正在努力的+按鈕提出了存儲在不同表格中的現有技能記錄列表(可預見的是技能表格)。 – Antag 2014-10-08 09:25:02

回答

1

這種更簡單的方法可以是使用人的屏幕上定義的彈出窗口(不AddPersonSkills對話框)。

在ViewPerson屏幕:

  1. 在屏幕設計的「彈出窗口」一節中,添加一個新的彈出
  2. 添加PersonSkills查詢(如果它已不存在)
  3. 將在PersonSkills查詢到你想讓它顯示在屏幕上的位置
  4. 正上方你添加,添加一個新的按鈕,指定操作打開創建
  5. 添加數據項彈出的「PersonSkills」列表中,選擇「查詢」,選擇「技能」
  6. 拖動「技能」查詢到的新的彈出
  7. 選擇加入
  8. 在「操作」屬性頁的部分的「技能」列表控件,點擊鏈接旁邊的「項塔」,選擇創建一個新的方法和插入以下

myapp.ViewPerson.Skills_ItemTap_execute = function(screen) { 
 
    var personSkill = new myapp.PersonSkill(); 
 
    personSkill.Person = screen.Person; 
 
    personSkill.Skill = screen.Skills.selectedItem; 
 
    msls.application.applyChanges(); 
 
    screen.closePopup(); 
 
};

這裏的代碼是什麼經驗,最終是荷蘭國際集團一樣(在我的例子,我有客戶,供應商和PreferredVendors作爲關係表(讓客戶可以有很多PreferredVendors))

enter image description here

如果需要,你可以在彈出的添加更多的字段:

  1. 添加數據項... - >本地地產(變型爲整數),將其命名爲SkillLevelProp
  2. 拖動SkillLevelProp財產上彈出
  3. 添加一個按鈕,彈出(選擇寫我自己的方法)
  4. 從技能水龍頭將上面的代碼按鈕的新方法(我們不能關閉彈出窗口上自來水了,因爲用戶需要還可以設置SkillLevel)

myapp.ViewPerson.submit_execute = function(screen) { 
 
    var prefSkill = new myapp.PersonSkill(); 
 
    prefSkill.Person = screen.Person; 
 
    prefSkill.Skill = screen.Skills.selectedItem; 
 
    prefSkill.SkillLevel = screen.SkillLevelProp; 
 
    msls.application.applyChanges(); 
 

 
    // clear out the SkillLevel value so it's empty the next time the popup is opened 
 
    screen.SkillLevelProp = null; 
 
    screen.closePopup(); 
 
};

這將使彈出如下圖所示:

enter image description here

這裏是彈出式的設計看起來:

enter image description here

+0

感謝您的回覆!所以我實現了這一點,當我只想爲一個人添加一項技能時,它運行良好。然而,一個人也有一個技能水平,代表他們對這項技能有多好,我不明白這種方法將如何讓用戶選擇技能和任何輸入或選擇技能水平。有任何想法嗎? – Antag 2014-10-13 07:10:16

+0

此外,您的方法似乎並不節省。我向該人添加新的personSkills(默認等級爲0),當我嘗試離開該人物實體時,它會要求我保存更改或丟棄它們。當我點擊保存所做的更改時,什麼都不會發生......當我點擊放棄時,他們將被丟棄,我可以離開。 – Antag 2014-10-13 08:03:06

+0

對不起,我錯過了關於SkillLevel的部分。我編輯了我的答案來解釋這一點。我的例子是保存記錄,所以不知道你的不同之處。我會盡快提供我的項目,以便您可以看一看。 – 2014-10-13 14:16:02