首页 \ 问答 \ 循环遍历foreach循环中的元素并从值中提取首字母缩略词,然后将另一个元素的值设置为派生的首字母缩略词(Loop through an element in the foreach loop and extract the acronym from the value and then set another element's value to the derived acronym)

循环遍历foreach循环中的元素并从值中提取首字母缩略词,然后将另一个元素的值设置为派生的首字母缩略词(Loop through an element in the foreach loop and extract the acronym from the value and then set another element's value to the derived acronym)

我正在接受在foreach迭代中循环遍历元素然后从元素中提取首字母缩略词,然后将另一个元素的值设置为派生首字母缩略词的挑战。

这是我的代码

1)cshtml:

foreach (var item in Model)
{                
     <h3 class="getName">@item.FullName</h3>
     [...]
     <h4 class="displayAvatar"></h4>
     [...]
}   

2)Jquery代码:

$('.getName').each(function (e) {
        var techieFullName = $('.getName').text();
        var getNameAcronym = techieFullName.match(/\b(\w)/g);
        var theName = getNameAcronym.join('');
        $('.displayAvatar').text(theName);
});

上面的代码将相同的结果(派生的首字母缩略词)分配给具有“displayAvatar”类的所有h4元素,但我希望每个全名都设置为每个首字母缩略词

我如何让它运转好吗? 欣赏


I'm having this challenge of looping through an element in a foreach iteration and then extract an acronym from the element, then set another element's value to the derived acronym.

Here's my code

1) cshtml:

foreach (var item in Model)
{                
     <h3 class="getName">@item.FullName</h3>
     [...]
     <h4 class="displayAvatar"></h4>
     [...]
}   

2) Jquery code:

$('.getName').each(function (e) {
        var techieFullName = $('.getName').text();
        var getNameAcronym = techieFullName.match(/\b(\w)/g);
        var theName = getNameAcronym.join('');
        $('.displayAvatar').text(theName);
});

The code above assigns the same result(derived acronym) to all h4 elements with class of "displayAvatar" but i want each fullname be set to each acronym

How do i get it running please? Appreciate


原文:https://stackoverflow.com/questions/46445376
更新时间:2022-08-15 09:08

最满意答案

您可以在任何需要的地方使用AsyncTask ,它可以位于ActivityFragment或其他任何类中。

对于你的问题,首先你应该检查位置可用性,而不是你的工作。

有关更多详细信息,请参阅AsyncTask


You can use AsyncTask anywhere you need, it can be in your Activity, Fragment or any other class.

For your question first you should check for location availability and than do your work.

For more details have a look at AsyncTask

相关问答

更多
  • 您可以在任何需要的地方使用AsyncTask ,它可以位于Activity , Fragment或其他任何类中。 对于你的问题,首先你应该检查位置可用性,而不是你的工作。 有关更多详细信息,请参阅AsyncTask You can use AsyncTask anywhere you need, it can be in your Activity, Fragment or any other class. For your question first you should check for locat ...
  • 您可以启动一个新的AsyncTask ,在其doInBackground方法(在后台线程上运行)下载图像,并在其onPostExecute方法(在UI线程上运行)中解除ProgressDialog 。 例如,在您的活动中: final Dialog progressDialog = ProgressDialog.show(this, title, message); //Should use DialogFragment to wrap the ProgressDialog new AsyncTask
  • 我发现这是从一个片段调用一个类 对linearLayout进行膨胀并将图表视图添加到布局中。 谢谢! I found this Calling a class from a fragment inflate a linearLayout and add chart view to the layout. Thanks!
  • 我认为这可能是一些问题。 多个Asynctasks无法同时运行,而Viewpagers默认情况下会加载3个视图。 我相信你需要调用:(如果你不想为所有需要加载的视图运行代码) if(getUserVisibleHint()) { //logic in here attemptLogin(); } 我相信这会阻止你的onCreateView()方法被调用3次。 因此,视图寻呼机具有以下方法: mPager.setOffscreenPageLimit(1); 这样做: Set the numb ...
  • 首先替换一个片段并不像刷新它。 是的,它会重新加载其中的每个视图以及数据。 但是你必须把它和你的新数据联系起来。 所以我会建议你在你的片段中创建一个刷新方法,并发送这个方法刷新数据,然后通知你的适配器为dataSetChanged 。 为了达到这个目的,你需要到达你当前附加的片段并调用其刷新方法。 您可以使用findFragmentByTag将其伸出。 编辑:澄清一点点 当你的AsyncTask完成后,你应该做这样的onPostExecute方法: ResultFragment resultFrag = ( ...
  • 我没有想出wt问题,但有另一种方法可以做到这一点。 我将在这里分享。 第一个接口类GetResult.class是相同的 第2次片段类myFrag.class中的更改 public class myFrag extends Fragment{ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.infla ...
  • 您应该使AsyncTask的onPostExecute方法向Tab2片段中的Receiver发送广播。 广播的东西:(在您的AsyncTask中) Intent intent = new Intent("someFilter"); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); 您还可以使用putExtra()将原始类型和对象作为附加项传递。 接收广播:(在你的Tab2片段中) // declare the receive ...
  • 由于您只需要在切换时取消,因此执行此操作的一种方法是公开fragment一些公共函数。 片段的切换最有可能发生在activity ,所以在替换之前,调用片段的暴露函数来取消asynctask 。 例如 在你的片段中: public void cancelAllTasks(){ // your logic to cancel tasks } 在活动中: yourFragment.cancelAllTasks(); ... replaceAnotherFragmentCode(); Since yo ...
  • public class DataAdapter extends RecyclerView.Adapter { private Context context; List jcontent; private maghalat fragment; public DataAdapter(Context context, List jcontent, maghalat frag) { this.c ...
  • 不要直接调用doInBackground ,而是调用execute (在异步任务上) Don't call doInBackground directly, call execute instead (on the async task)

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)