Tag Archives: JavaScript

Txoj kev sai thiab yooj yim: Ua kom muaj ib qhov chaw SharePoint siv so

Muaj ntau ntau pab ib ncig uas qhia tau tias yuav ua li cas, tab sis kuv nrhiav tsis tau ib tug muab mus-mus txuas, yog li no peb cov.

Koj muaj peev xwm tsim ib qhov chaw SharePoint siv API so.  Ntawm no yog ib tug piv txwv ci siab:

<!--
    SiteRequestForm.html: Sau xov xwm thiab tsim tau ib qhov chaw rau cov neeg siv.
-->

<chaw>
<cov lus>
    <tr>
        <Td>Rau npe:</Td>
        <Td><tswv yim hom= "ntawv nyeem" lub npe= "SiteName" tus ID= "SiteName" /></Td>
    </tr>
    <tr>
        <Td colspan= "2">
            <tswv yim hom= "xa ntawv" tus ID= "CreateSiteButton" tus nqi= "Tsim lub Site" />
        </Td>
    </tr>
</cov lus>
</chaw>

<tsab ntawv src="../Plugins/jquery-1.11.0.min.js"></tsab ntawv>

<tsab ntawv>
Var CreateSiteLogicContainer = {

    createSiteData: {
            "tsis": {
                __metadata: { "hom": "SP.WebInfoCreationInformation" },
                Url: "Paultest1",
                Npe: "Paultest1",
                Hauj lwm lawm: "tsim so web los ntawm Paul!",
                Hais lus: 1033,
                WebTemplate: "sts",
                UseUniquePermissions: tsis tseeb
            }
    },

    createSite: muaj nuj nqi () {

        jQuery.support.cors = tseeb;

        CreateSiteLogicContainer.createSiteData.parameters.Url = $("#SiteName").val();
        
        $.ajax({
            url: "https://bigapplesharepoint.sharepoint.com/NBAIADev/_api/web/webinfos/add",
            txujci: "NCEJ",

            headers: {
                "Txais": "daim ntawv thov/json; odata = verbose",
                "cov ntawv hom": "daim ntawv thov/json;odata = verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },

            cov ntaub ntawv: JSON.stringify(CreateSiteLogicContainer.createSiteData),

            zoo: muaj nuj nqi () { alert("zoo"); },
            yuam kev: muaj nuj nqi () { alert("kev ua yuam kev"); }

        });
    },

    wireUpForm: muaj nuj nqi () {
        $("#CreateSiteButton").nyem(muaj nuj nqi () {
            alert("Li mus sim thiab tsim tau lub site.");
            CreateSiteLogicContainer.createSite();
        });
    }


}

CreateSiteLogicContainer.wireUpForm();

</tsab ntawv>

Thaum zoo, koj tau ib tug JSON tuaj rau lawv teb li no:

image

Kuv xav tseem ceeb thiab learnings ntawm no muaj xws li:

  • Kauj siv jQuery.  Hauv kuv tsev neeg, Kuv lub tsev qiv ntawv jQuery nyob rau hauv "../ plugins. "  Koj mam li xav hais tias yuav kis tau mus rau qhov chaw koj nyiam JQ nyob.
  • Luam thiab paste ntawd cov snippet tag nrho rau hauv ib cov ntawv Editor Web feem ntawm ib sab thiab nws yuav tsum ua hauj lwm xwb fine.  Koj mam xav hloov tag kis API hu thiab xyuas kom tseeb tias koj siv JQ kom raug.
  • Qhov URL yog ntu koj API endpoint.  Hauv kuv tsev neeg, Nws yog ib txoj kev kom ncua chaw kom https://bigapplesharepoint.com
  • Koj tsis tas yuav muab cov ntsiab lus-ntev. Ib co posts uas nyuam thiab MSDN daim ntawv implies tias koj tsis, tab sis tshwm sim rau kuv tau, uas kuv xav tias yog raug leej twg rau $.ajax hu rau nws tus kheej.
  • Cov kab no yuav tsum tau kom tsis txhob muaj qhov lus teb "forbidden": "X-RequestDigest": $("#__REQUESTDIGEST").val().  Muaj ntau hom kev ua, tab sis qhov no yog qhov zoo zoo nkauj.  Kuv tau poob qhov link rau blog muab no shortcut.  H/T rau koj, mysterious blogger!

Hmoov zoo thiab vam cia qhov no yuav pab lwm tus neeg paub.

</kawg>

undefinedSubscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Yooj yim thiab ceev thaum: SharePoint so hu xwb rov qab los 100 Cov ntaub ntawv

Kuv twb ua haujlwm rau ib tug pej xeem facing qhov web site rau kuv SharePoint xyaum no nyob rau hauv New York thiab nws siv ntau hu JavaScript thiab so kom txaus los qhia tias cov.

Thaum lub caij kev khiav, Kuv tsim tau ib dataset me me uas nyuam qhuav 10 los thiaj natwm nyob rau hauv ib daim ntawv teev kev cai thiab kuv tus so txhua txhua rho tawm ntawd.  Thaum kuv tsoo tau daim ntawv los tau ob peb puas natwm cov ntaub ntawv kuaj kev muab hlob, Kuv pom tias kuv tau txais raws nraim 100 xa rov qab rau kuv tus so hu natwm.

Qhov no nws yog ib tug yooj yim heev tshaj plaws rau qhov chaw nyob.  Hauv kuv tsev neeg (thiab kuv ntseeg tias feem ntau), lub neej ntawd so hu rau SharePoint (thiab tejzaum nws ua ib qho kev lag luam txheem?) rov qab los 100 natwm.  Rov qab mus tshaj lub neej ntawd, siv cov $top parameter rau koj, raws li nyob rau hauv:

TAU /Insights Dev/_api/web/lists/GetByTitle('MockBlog')/khoom?$xaiv = ID,Npe,Pawg/Title,Blog_x0020_Author/Title,DatePublished,BlogSummary&$nthuav = Blog_x0020_Author,Pawg&$lim =&$saum = 9999

Kuv yuav khaws 9999 qhov no lawm kuv paub hais tias growth-wise, yuav tsis muaj ntau tshaj 200 los luaj natwm ntxiv rau daim ntawv nyob hauv ib lub xyoos.  Yog hais tias nws yuav ungainly, peb yuav tau siv ib co paging sibtsoo.

</kawg>

undefinedSubscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin

Tus txiv neej tsis tus Caching hauv JavaScript

[TL;DR version: siv cov ncuav qab zib kom cia ntsuam async hu; kav soj ntsuam lawm hais lus async tam sim ntawd thiab ces validate lawv tom qab nplooj load.]

Kuv twb tau ua rau ntawm qhov chaw intranet SharePoint rau ib tug neeg ntawd nta, cov lwm yam, ib stylized lwm yam navigation uas los ntawm kev xaiv zaub mov muaj tswj ntawm ib txwm qub kev cai sau.  Tsab cai idea yog tias tus neeg twg thiaj tau tus tswj "lawv" rau cov zaub mov uas tsis rau los muab cuam tshuam los ntawm lub ntiaj teb no navigation muab tso los ntawm nws.

(muaj dab tsi subversive incredibly txog ntxiv ib CEWP uas cov ntsiab lus rau ib tug HTML uas loads ib co CSS thiab JS fundamentally tshwm sim yuav luag txhua yam hais txog tus kawm li cwjpwm... tiam sis yog rau lwm tus ncej)

Qhov chaws kom yooj yim yuav zoo nkauj no:

  • Tos li cov nplooj ntawv kom tag rau nraum chaw thau khoom thiab muab ib tug async hu mus thauj tuaj tshuab raj ua ib yam khoom ntawm ib daim ntawv teev tas los yog lists.asmx los yog los xijpeem
  • Siv jQuery, dynamically populate ib Rev yog <lis>tus hauv ib tug niam txiv <ul> (saib cov Christian Pinder tsab xov xwm no rau lub vaj no tecnnique simplistic)
  • Kev siv CSS yuav ua txhua yam rau formatting
  • Nyiaj!

Tej teev hauv no mob ntawd yog txhua zaus thaum leej twg hits yog ib cov chaw nplooj, tus neeg ntawd lub web browser yog caw kom tau yam khoom los ntawm daim ntawv.  Thaum dev no tiav thiab kuaj tau proven yam yuav ruaj thiab teb, no hu no hu ruaj dua 99% lub sij hawm thaum cov zaub mov tsis tshua hloov.  Nws kuj muaj ib tug weird UI muaj uas muaj nyob rau qhov brave new world ntawm cus-ajaxy web sites – cov phab renders thiab xwb ces yog cov ntawv qhia zaub mov kav.  Nws yog jittery thiab distracting rau kuv saib.  Thiab jittery. Li ntawd, caching. 

Kuv raug kho qhov logic thusly:

  • Nrhiav ib cov kua nplaum uas nyob rau hauv qhov browser uas muaj daim ntawv qhia zaub mov li kuv kawg nyeem nws
    • Yog nrhiav tau, kav nws tam sim ntawd.  Tsis txhob tos txog rau sab mus tag rau nraum chaw thau khoom.  (Koj yuav tau xyuas kom tseeb tias koj cov HTML leeg muab tso ntawm no, tab sis nws yuav tsis ua zog).
  • Tos li cov nplooj ntawv kom tag rau nraum chaw thau khoom thiab muab ib tug async hu mus thauj tuaj tshuab raj ua ib yam khoom ntawm ib daim ntawv teev tas los yog lists.asmx los yog los xijpeem
  • Piv li kuv tau tiv cov kua nplaum uas
    • Yog hais tias nws qhov khoom, TSO TSEG
    • Txwv tsis pub, siv jQuery, dynamically populate ib Rev yog <lis>cov nyob hauv lub <ul>
  • Kev siv CSS yuav ua txhua yam rau formatting
  • Nyiaj!

Qee yam uas koj yuav hais, "hav! yog tsis muaj real caching mus rau hauv no vim muaj koj nyob nraum nyeem cov ntawv qhia zaub mov rau nkawv noj txhua txhua zaug uas koj nkaus xwb.”  Thiab koj nyob nraum txoj kev-kuv tsis muab rau tus neeg rau zaub mov ntais txhua yam.  Tab sis vim hu yog async thiab tshwm sim tom qab uas pib ntawm nplooj ntawv HTML payload siab renders, nws "yim" noog kom tus neeg siv.  Daim ntawv qhia zaub mov renders zoo nkauj ntau li cov nplooj draws.  Yog hais tias cov zaub mov zoo li yuav hloov, cov neeg siv yog nyuam ib jittery rov kos ntawm cov ntawv qhia zaub mov, tab sis lub caij ntawd xwb.

Yog cov kev ua no caching zoo tshaj thiab pab kom paub cov neeg rau zaub mov txhij:

  • Muab tso rau hauv ib txoj cai tias tus tus "kua nplaum uas cache" yog muaj tsawg kawg yog 24 teev los yog ib txhia timeframe. Tsuav yog tsis DRA cov kua nplaum uas, siv cov kua nplaum uas tshuab raj snapshot thiab tsis txhob ntaus cov neeg rau zaub mov.

Qhov tshij... uas txhua yam uas tuaj siab tamsim no :). 

Yog leej twg muaj tus muaj cov tswv yim ntse nov kuv yuav hlub kom paub tias lawv.

Thiab ntsig – cov txheej txheem no yuav raug siv rau lwm yam khoom.  No neeg sab muaj ntau yam ntaub ntawv-uas tau tsav ntawv teev rau phab ntau, muaj coob leej kuj tsis tshua hloov (zoo li ib zaug ib lub lim tiam los sis ib hlis ib zaug).  Yog tias koj phiaj txog tej chaw functionality, koj muab tau ib daim UI feem ntau yog rub cov ntsiab lus los ntawm cov kua nplaum uas nyob tom khw thiab rendering tam sim ntawd.  Nws yim sai rau cov neeg siv txawm hais tias koj nyob nraum tsis txuag cov neeg rau zaub mov twg Pest.  Koj tau txuag cov neeg rau zaub mov mus los ntawm kev txiav txim siab rau tej mob uas muaj tej yam rau invalidate no qhov chaw cov kua nplaum uas cache.  Li no tag situational thiab artsy khoom thiab tiag tiag mas kev lom zem :). 

</kawg>

undefinedSubscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin