Javascript 如何对不同内容使用同一警报(?)

Javascript 如何对不同内容使用同一警报(?),javascript,angularjs,underscore.js,lodash,Javascript,Angularjs,Underscore.js,Lodash,快速提问 我使用角度带显示一些警报,每个警报都在不同的变量中,但我想避免这样做,有人告诉我使用lodash的。扩展,但在这种特殊情况下我应该如何使用它 var loaderAlert1 = $alert({ animation: 'fx-bounce-right', content: 'Loading content, please wait...', container: '.alerts-container', type: 'info', show:

快速提问

我使用角度带显示一些警报,每个警报都在不同的变量中,但我想避免这样做,有人告诉我使用lodash的
扩展,但在这种特殊情况下我应该如何使用它

var loaderAlert1 = $alert({
    animation: 'fx-bounce-right',
    content: 'Loading content, please wait...',
    container: '.alerts-container',
    type: 'info',
    show: true
  }),
  loaderAlert2 = $alert({
    animation: 'fx-bounce-right',
    content: 'Adding Line to BetSlip',
    container: '.alerts-container',
    type: 'info',
    show: false
  }),
  loaderAlert3 = $alert({
    animation: 'fx-bounce-right',
    content: 'Loading your messages, please wait...',
    container: '.alerts-container',
    type: 'info',
    show: false
  });
如您所见,几乎相同,但在某些情况下,show attr设置为true或false,并且
内容:
也会更改

我调用此警报的方式:
LoaderErt1.show()
LoaderErt1.hide()
等等

所以我想做一些类似的事情

var loaderAlert = $alert({
    animation: 'fx-bounce-right',
    content: 'Loading content, please wait...',
    container: '.alerts-container',
    type: 'info',
    show: true
  });

loaderAlert = {content: 'loading something else'};

loaderAlert = {content: 'loading something GREAT'};

loaderAlert = {content: 'loading only ROCK N ROLL'};

在这里,我只声明一个变量,然后一旦调用该变量,我就可以更改
内容:
。。。但是我不知道如何扩展

我认为这应该可以做到:

   function customAlert( content ) {
         var loaderAlert = $alert({
            animation: 'fx-bounce-right',
            content: content,
            container: '.alerts-container',
             type: 'info',
            show: true
          });

         return loaderAlert;
    }
Бdit:

var content = 'loading something else', // choose one of the three choices here
     loaderAlert = customAlert(content);

我认为这应该起作用:

   function customAlert( content ) {
         var loaderAlert = $alert({
            animation: 'fx-bounce-right',
            content: content,
            container: '.alerts-container',
             type: 'info',
            show: true
          });

         return loaderAlert;
    }
Бdit:

var content = 'loading something else', // choose one of the three choices here
     loaderAlert = customAlert(content);

我认为这应该起作用:

   function customAlert( content ) {
         var loaderAlert = $alert({
            animation: 'fx-bounce-right',
            content: content,
            container: '.alerts-container',
             type: 'info',
            show: true
          });

         return loaderAlert;
    }
Бdit:

var content = 'loading something else', // choose one of the three choices here
     loaderAlert = customAlert(content);

我认为这应该起作用:

   function customAlert( content ) {
         var loaderAlert = $alert({
            animation: 'fx-bounce-right',
            content: content,
            container: '.alerts-container',
             type: 'info',
            show: true
          });

         return loaderAlert;
    }
Бdit:

var content = 'loading something else', // choose one of the three choices here
     loaderAlert = customAlert(content);

.extend
会对您有所帮助,但在调用
$alert
时重新使用对象可能不是个好主意-您可能会发现以后需要返回到给定的
内容

如果您提供一个新对象作为
.extend
的第一个参数,则可以克隆每个警报的基本参数:

var base = {
    animation: 'fx-bounce-right',
    content: 'Loading content, please wait...',
    container: '.alerts-container',
    type: 'info',
    show: true
  }

$alert(_.extend({}, base, { content: 'first alert' }));
$alert(_.extend({}, base, { content: 'second alert' }));
$alert(_.extend({}, base, { content: 'third alert' }));

.extend
会对您有所帮助,但在调用
$alert
时重新使用对象可能不是个好主意-您可能会发现以后需要返回到给定的
内容

如果您提供一个新对象作为
.extend
的第一个参数,则可以克隆每个警报的基本参数:

var base = {
    animation: 'fx-bounce-right',
    content: 'Loading content, please wait...',
    container: '.alerts-container',
    type: 'info',
    show: true
  }

$alert(_.extend({}, base, { content: 'first alert' }));
$alert(_.extend({}, base, { content: 'second alert' }));
$alert(_.extend({}, base, { content: 'third alert' }));

.extend
会对您有所帮助,但在调用
$alert
时重新使用对象可能不是个好主意-您可能会发现以后需要返回到给定的
内容

如果您提供一个新对象作为
.extend
的第一个参数,则可以克隆每个警报的基本参数:

var base = {
    animation: 'fx-bounce-right',
    content: 'Loading content, please wait...',
    container: '.alerts-container',
    type: 'info',
    show: true
  }

$alert(_.extend({}, base, { content: 'first alert' }));
$alert(_.extend({}, base, { content: 'second alert' }));
$alert(_.extend({}, base, { content: 'third alert' }));

.extend
会对您有所帮助,但在调用
$alert
时重新使用对象可能不是个好主意-您可能会发现以后需要返回到给定的
内容

如果您提供一个新对象作为
.extend
的第一个参数,则可以克隆每个警报的基本参数:

var base = {
    animation: 'fx-bounce-right',
    content: 'Loading content, please wait...',
    container: '.alerts-container',
    type: 'info',
    show: true
  }

$alert(_.extend({}, base, { content: 'first alert' }));
$alert(_.extend({}, base, { content: 'second alert' }));
$alert(_.extend({}, base, { content: 'third alert' }));



太好了,我该怎么隐藏?太好了,我该怎么隐藏?太好了,我该怎么隐藏?太好了,我该怎么隐藏?隐藏?将show属性更改为false,并在我执行
loaderAlert.hide()
之前使用类似于
ng show=“loaderAlert.show”
的内容,这就是我的意思。无论如何,您的解决方案不起作用,它没有显示带有内容的警报,它只是一个没有字母的白色警报?将show属性更改为false,并在我执行
loaderAlert.hide()
之前使用类似于
ng show=“loaderAlert.show”
的内容,这就是我的意思。无论如何,您的解决方案不起作用,它没有显示带有内容的警报,它只是一个没有字母的白色警报?将show属性更改为false,并在我执行
loaderAlert.hide()
之前使用类似于
ng show=“loaderAlert.show”
的内容,这就是我的意思。无论如何,您的解决方案不起作用,它没有显示带有内容的警报,它只是一个没有字母的白色警报?将show属性更改为false,并在我执行
loaderAlert.hide()
之前使用类似于
ng show=“loaderAlert.show”
的内容,这就是我的意思。无论如何,您的解决方案不起作用,它不会显示包含内容的警报,这只是一个没有文字显示的白色警报。一旦我决定调用它,我应该使用它吗?知道如何隐藏它吗?@NietzscheProgrammer你的意思是,也更改了show属性?我的意思是,在我执行
loaderAlert.hide()
之前,警报会消失。差不多that@NietzscheProgrammer我不明白你为什么现在也不能这么做。一旦我决定调用它,我应该如何使用它?知道如何隐藏它吗?@NietzscheProgrammer你的意思是,也更改show属性?我是说,在我执行
Loaderlert.hide()
之前,警报会消失。差不多that@NietzscheProgrammer我不明白你为什么现在也不能这么做。一旦我决定调用它,我应该如何使用它?知道如何隐藏它吗?@NietzscheProgrammer你的意思是,也更改show属性?我是说,在我执行
Loaderlert.hide()
之前,警报会消失。差不多that@NietzscheProgrammer我不明白你为什么现在也不能这么做。一旦我决定调用它,我应该如何使用它?知道如何隐藏它吗?@NietzscheProgrammer你的意思是,也更改show属性?我是说,在我执行
Loaderlert.hide()
之前,警报会消失。差不多that@NietzscheProgrammer我不明白你为什么现在也不能这样做。