preface

In the recent development process encountered such a problem, the same two activities, one is the Spring Festival activity, the other is the Lantern Festival activity, about the user uploaded works during the activities of the first review, review, query ah, friends may ask, so simple encountered what problem, curious words continue to watch!

A curious brain circuit

  • Since the background pages of these two kinds of activities are exactly the same, because this is the demand assigned to me by the head of the department during the meeting on Monday, the idea in my mind at first is that it is not too difficult, that is, the IDS of the two types of activities are different, it is ok to complete one set, copy another set, and change the ID, there is no problem.
  • Just as I was thinking, the department boss gave me directions, let me do a set of good, according to the activity ID do not have to pull to different tasks. “I said casually.
  • After the meeting, I started a meditation (this process is reflected his small white, inexperienced), I think it is not like before a drop-down choice, can determine directly, it can still happen, want ah, finally have the looks, the entrance of the configuration menu, use the type in the address bar to distinguish the two types, and then to the background, you can get the activity id, Then have an idea and start doing it.

The implementation process

First, I set up the path menu, and then I started thinking about how to get the value of type in the address bar, because there is a parameter after the address bar, and I didn’t think much about it. I just wanted to ‘cut the string’ and get the number after ‘type=’. The code looks like this:

var locUrl = "http://localhost:88/music/index.html? id=1"    // This is a local link
var type = locUrl.substring(locUrl.lastIndexOf("=") +1);     // Intercept the value of type
console.log(type);  // Output: 1


Copy the code

To think that you can after ~ and then continue to develop, continue to do, soon, completed the activity management backend interface development, and then to tell the boss completed project, the boss asked me very responsible heart, do a few sets, I say a set, he asked me how I realized, I told him about, he said after open I see code, see when there is a problem, Although I got it, but if I continue to concatenate parameters in the following, how to do this is not very flexible, not desirable, after his patient guidance, I probably know, to use the parameter name to take, so there is the following code:

function GetQueryValue(queryName) {
     var query = decodeURI('http://localhost:88/music/index.html? Id = 1 & actName = New Year '.substring(1));
     var vars = query.split("&");
     for (var i = 0; i < vars.length; i++) {
         var pair = vars[i].split("=");
        if (pair[0] == queryName) { return pair[1]; }}return null;
 }
 var queryVal=GetQueryValue('actName');
 console.log(queryVal);  / / the Spring Festival
Copy the code

It seems all is easy to understand, two ways, one is the access to intercept string parameters, the other is to through the parameter name you need to find the attribute values, I think two ways can be, but, according to the rationality, the modified code, more practical, in the actual project development fast ~

summary

For such a long time, although the projects I came into contact with were not too difficult, I could learn some knowledge from them and also find my own deficiencies in practice. On address bar interception parameters may be for junior partner may be very simple, but in the actual project scenarios, especially for just entering in the work of the new small white, various conditions scene confuse us, this needs us, ‘through’ – ‘find nature’ – ‘many thinking, patience analysis’, find the most reasonable method to solve, I believe my friends will have some gains in this process. Let’s work together

Front road, long haul, stepping on pit ing, summary ING, review ing, continuous update…