小编Lun*_*una的帖子

angularjs组件在模板中获取表单

所以我有一个包含表单的模板的组件.

mycomponent.html:

<div>
    <form name="myForm"> 
        <!-- more html code -->
    </form>
</div>
Run Code Online (Sandbox Code Playgroud)

如何在组件控制器中访问myForm?目前我正在注入$ scope来从中获取它.或者这是获得表格的唯一方法吗?

编辑:添加一些代码,以更好地说明在JavaScript中

angular.module('example')
.component('myComponent', {

    templateUrl: 'mycomponent.html',
    controller: function($scope) {
         $scope.myForm // This works
         this.myForm // undefined, can I access it through the component scope instead of $scope somehow? 
    }
 });
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-components

11
推荐指数
1
解决办法
1万
查看次数

IQueryable <T>给出与List <T>不同的结果

如果我在我的实体框架结果上使用Select on IQueryable,那么我将得到4个项目.

如果我在IQueryable.ToList()上使用Select,我会得到所有36个项目.

这是函数的代码:

public ImagesGetModelView Get(int start, int count)
{
    if (count <= 0) count = 9;
    else if (count > ImageHandler.MaxResult) count = ImageHandler.MaxResult;    

        IQueryable<Image> imagesList = ImagesHandler.FetchRangeScore(start, count)
           .Where(m => m.Domain == Database.Enums.ImageDomain.Gfycat);

        //Works using list :(
        //var list = imagesList.ToList();

        //Select all subreddits once
        //Returns 4 instead of 36 if not using the list ...
        //Returns 1 instead of 2 with Distinct() if not using the list
        IEnumerable<Subreddit> subreddits = imagesList
           .Select(m => m.Subreddit); //.Distinct(); …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework

10
推荐指数
2
解决办法
527
查看次数

膨胀javascript文件以使其更大

这是一个相当奇怪的问题,但我需要增加javascript文件的文件大小,因为你通常想减小大小:)

所以我想知道什么是使用无用代码膨胀javascript文件的最佳方法,但是让浏览器尽可能快地解析javascript文件,并希望尽可能少地使用内存.

我想到的方法可能只是放了很多这些,直到达到所需的文件大小.function(){return undefined; };

javascript performance

5
推荐指数
1
解决办法
226
查看次数

boost :: function静态成员变量

我试图将boost :: function存储为静态变量,其中"reference?" 是从函数中获取的.

变量看起来像这样:

static boost::function<void( const wchar_t*, const bool)> s_logMessage;
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时,我收到错误:

错误LNK2001:未解析的外部符号"public:static class boost :: function Gorbatras_Converter :: ConverterApp :: s_logMessage"(?s_logMessage @ ConverterApp @ Gorbatras_Converter @@ 2V?$ function @ $$ A6AXPB_W_N @ Z @ boost @@ A)

我注意到,如果我不使用变量,我可以编译它没有那个错误(猜测它是一个编译器优化,因为它没有使用)但是一旦我尝试使用s_logMessage变量我得到链接器错误.

我设置s_logMessage的方式如下:

const int ConverterApp::RunConverter( boost::function<void( const wchar_t* a_message, const bool a_newLine)> a_logMessage )
{
    ConverterApp::s_logMessage = a_logMessage;    
    ...
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试将其设置为非静态成员变量,然后它似乎工作.但我需要它作为静态,否则我可能只是将它作为一个参数,我不想要它,因为它将是很多功能.

如果你想知道为什么我发送一个日志函数作为参数,那是因为它来自一个单独的程序.

所以我需要帮助的是如何在一个静态变量中保存boost :: function函数?

c++ boost

0
推荐指数
1
解决办法
439
查看次数